题意:有长为n的串,其中有几个[ll,rr]符合条件。
首先,长度超过9的串一定符合条件。枚举左端点ll,右端点控制在ll+8就行,剩下的直接加。
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #include <cstring> #include <map> #include <queue> #include <set> #include <cassert> #include <stack> #include <bitset> #define mkp make_pair #define err cout<<"err"<<endl using namespace std; const double EPS=1e-8; typedef long long lon; typedef unsigned long long ull; typedef pair<int,int> pii; const lon SZ=300010,SSZ=SZ*SZ,APB=4,one=1; const lon INF=0x3f3f3f3f,mod=1000000007; lon n; char ch[SZ]; void init() { cin>>ch+1; n=strlen(ch+1); lon res=0; for(lon i=1;i<=n;++i) { if(n>=i+8) { res+=n-(i+8)+1; } bool ok=0; for(lon p=i+1;p<=min(n,i+7)&&!ok;++p) { for(int k=p-1;k>=i&&!ok;--k) { lon j=k-(p-k); if(j>=i&&ch[j]==ch[k]&&ch[k]==ch[p]) { lon tmp=min(n,i+7)-p+1; //cout<<"i: "<<i<<" "<<tmp<<endl; res+=tmp; ok=1; break; } } } } cout<<res<<endl; } void work() { } void release() { } int main() { std::ios::sync_with_stdio(0); //freopen("d:\\1.txt","r",stdin); lon casenum; //cin>>casenum; //cout<<casenum<<endl; //for(lon tim=1;tim<=casenum;++tim) //for(lon tim=1;cin>>n;++tim) { //cout<<"Case #"<<tim<<": "; init(); work(); release(); } return 0; }