QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#574174#8521. Pattern Search IIyanshanjiahongTL 0ms0kbC++201.6kb2024-09-18 20:59:182024-09-18 20:59:18

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 20:59:18]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-09-18 20:59:18]
  • 提交

answer

#include<bits/stdc++.h>
#include<bits/extc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define repp(i,j,k) for(int i=j;i>=k;i--)
#define ls(x) (x<<1)
#define rs(x) ((x<<1)|1)
#define mp make_pair
#define sec second
#define fir first
#define pii pair<int,int>
#define lowbit(i) i&-i
using namespace std;
typedef long long ll;
const int N=2e5+5,M=1e6+5,S=(1<<15)+5,inf=1e9+7,mo=1e9+7;
void read(int &p){
	int x=0,w=1;
	char ch=0;
	while(!isdigit(ch)){
		if(ch=='-')w=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	p=x*w;
}
int n,fib[45],cntf,sid;
char s[N];
int f[N][40];
int check(int dep,int le,int ri,int ql,int qr,int stp){
    if(ql<=le&&qr>=ri)return f[stp][dep];
    int mid=le+fib[dep-1]-1,res=stp;
    if(ql<=mid)res=check(dep-1,le,mid,ql,qr,res)+1;
    if(qr>mid)res=check(dep-2,mid+1,ri,ql,qr,res)+1;
    return res-1;
}
signed main(){
    read(sid);
    scanf("%s",s+1);
    n=strlen(s+1);
    fib[0]=fib[1]=1,cntf=1;
    while(fib[cntf]<3*n)
        cntf++,fib[cntf]=fib[cntf-1]+fib[cntf-2];
    rep(i,1,3)
        cntf++,fib[cntf]=fib[cntf-1]+fib[cntf-2];
    rep(i,1,n){
        if(s[i]=='a')f[i][1]=i,f[i][0]=i-1;
        else f[i][0]=i,f[i][1]=i-1;
    }
    rep(j,2,cntf){
        rep(i,1,n)
            f[i][j]=(f[i][j-1]==n?n:f[f[i][j-1]+1][j-2]);
    }
    int j=0,ans=inf;
    rep(i,1,fib[cntf]){
        if(j<i)j=i;
        while(j<=fib[cntf]&&check(cntf,1,fib[cntf],i,j,1)<n)
            j++;
        if(j>fib[cntf])break;
        ans=min(ans,j-i+1);
    }
    printf("%d\n",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

aabbaab

output:


result: