CF1168B Good Triple
作者:互联网
codeforces
简单题,考虑这个串只有0,1两种字符。所以每9个必有一组合法的情况
所以暴力的复杂度是\(O(9n)\)
代码:
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
#define rg register
void read(int &x){
char ch;bool ok;
for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
const int maxn=3e5+10;
int n,las=1e9,d[maxn];long long ans;char a[maxn];
int main(){
scanf("%s",a+1),n=strlen(a+1);
for(rg int i=1;i<=n;i++)
for(rg int j=1;i+j*2<=n;j++)
if(a[i]==a[i+j]&&a[i+j*2]==a[i]){d[i]=i+j*2;break;}
for(rg int i=n;i>=1;i--){
if(d[i])las=min(las,d[i]);
if(las!=1e9)ans+=n-las+1;
}
printf("%lld\n",ans);
}
标签:ch,ok,int,Good,Triple,ans,include,CF1168B,las 来源: https://www.cnblogs.com/lcxer/p/11404471.html