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);
}
posted @ 2019-08-24 13:53  蒟蒻--lichenxi  阅读(210)  评论(0编辑  收藏  举报