QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#444112 | #8521. Pattern Search II | ucup-team3510# | WA | 47ms | 93976kb | C++20 | 1.3kb | 2024-06-15 17:21:09 | 2024-06-15 17:21:09 |
Judging History
answer
#include <bits/stdc++.h>
#define N 5000011
#define link irbvoovr
using namespace std;
char s[N];int n,ch[N*2][2],ed[N*2],link[N*2],len[N*2],siz[N*2],lst,sz;long long ans;
void saminit(){link[0]=-1;len[0]=0;lst=0;}
void append(char s)
{
int nw=++sz;ed[sz]=1;len[nw]=len[lst]+1;int p=lst;lst=nw;
while(~p&&!ch[p][s-'a'])ch[p][s-'a']=nw,p=link[p];
if(!~p){link[nw]=0;return;}
int q=ch[p][s-'a'];
if(len[p]+1==len[q])link[lst]=q;
else
{
int cl=++sz;
link[cl]=link[q];
for(int i=0;i<2;++i)ch[cl][i]=ch[q][i];
len[cl]=len[p]+1;
link[q]=link[nw]=cl;
while(~p&&ch[p][s-'a']==q)ch[p][s-'a']=cl,p=link[p];
}
}
char S[N],nS[N];
const int B=5e6;
void dfs(int u,int cur,int len)
{//printf("dfs(%d,%d,%d)\n",u,cur,len);
if(u==n+1){printf("%d\n",len);exit(0);}
if(ch[cur][s[u]-'a'])dfs(u+1,ch[cur][s[u]-'a'],len+1);
if(ch[cur][!(s[u]-'a')])dfs(u,ch[cur][!(s[u]-'a')],len+1);
}
int main()
{
scanf("%s",s+1);n=strlen(s+1);
int cnt0=1,cnt1=0;S[1]='a';
while(cnt0*2+cnt1<=B)
{
int nc=0;
for(int i=1;i<=cnt0+cnt1;++i)
{
if(S[i]=='b')nS[++nc]='a';
else nS[++nc]='a',nS[++nc]='b';
}
cnt0=cnt1=0;
for(int i=1;i<=nc;++i)S[i]=nS[i],cnt0+=S[i]=='a',cnt1+=S[i]=='b';
}
// printf("S:%s\n",S+1);
saminit();
for(int i=1;i<=cnt0+cnt1;++i)append(S[i]);
dfs(1,0,0);
}
详细
Test #1:
score: 100
Accepted
time: 31ms
memory: 90620kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 40ms
memory: 88296kb
input:
a
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 33ms
memory: 88588kb
input:
b
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 31ms
memory: 92176kb
input:
aa
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 27ms
memory: 93324kb
input:
bb
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 38ms
memory: 88332kb
input:
ab
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 31ms
memory: 90632kb
input:
ba
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 38ms
memory: 93976kb
input:
bbba
output:
7
result:
ok 1 number(s): "7"
Test #9:
score: 0
Accepted
time: 19ms
memory: 93120kb
input:
abbbbbbbab
output:
20
result:
ok 1 number(s): "20"
Test #10:
score: 0
Accepted
time: 47ms
memory: 93744kb
input:
abbbbabbbabbbabbabaabbabb
output:
43
result:
ok 1 number(s): "43"
Test #11:
score: -100
Wrong Answer
time: 33ms
memory: 93208kb
input:
bbbaabaabbbaabababbbabaaabaaabbbaaaabaabaaaaabbabbbababbabaaba
output:
96
result:
wrong answer 1st numbers differ - expected: '94', found: '96'