QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#606289 | #8701. Border | Mirasycle | 23 | 4ms | 28272kb | C++14 | 1.5kb | 2024-10-03 00:25:37 | 2024-10-03 00:25:37 |
Judging History
answer
#include<bits/stdc++.h>
#define push_back emplace_back
#define fi first
#define se second
#define make_pair mp
using namespace std;
typedef long long ll;
const int maxn=4e6+10;
const int mod=1e9+7;
char s[maxn],t[maxn];
ll p[maxn],h[maxn]; int pos;
int z[maxn],ans[maxn],c[maxn],n;
int id(char cha){ return cha-'a'+1; }
ll gethash(int l,int r){
if(l>r) return 0;
if(pos>r||pos<l) return (mod+h[r]-h[l-1]*p[r-l+1]%mod)%mod;
else return (gethash(pos+1,r)+1ll*id(t[pos])*p[r-pos]%mod+1ll*gethash(l,pos-1)*p[r-pos+1]%mod)%mod;
}
bool chk(int l1,int r1,int l2,int r2){ return gethash(l1,r1)==gethash(l2,r2); }
void chkmax(int &x,int y){ x=x>=y?x:y; }
void init(){
n=strlen(s+1); p[0]=1;
for(int i=1;i<=n;i++) p[i]=1ll*p[i-1]*131%mod;
for(int i=1;i<=n;i++) h[i]=(1ll*h[i-1]*131%mod+id(s[i]))%mod;
}
int main(){
cin>>(s+1)>>(t+1); init();
z[1]=n; int l=0,r=0;
for(int i=2;i<=n;i++){
z[i]=i>r?0:min(r-i+1,z[i-l+1]);
while(s[1+z[i]]==s[i+z[i]]&&i+z[i]<=n) z[i]++;
if(i+z[i]-1>r) r=i+z[l=i]-1;
}
int best=0; memset(ans,0,sizeof(ans));
for(int i=1;i<=n;i++)
if(i+z[i]>n) chkmax(best,n-i+1),c[n-i+1]++;
else{
pos=i+z[i]; if(chk(1,n-i+1,i,n)) chkmax(ans[pos],n-i+1);
pos=z[i]+1; if(chk(1,n-i+1,i,n)) chkmax(ans[pos],n-i+1);
}
int cur=0;
for(int i=1;i<=n/2;i++){
chkmax(ans[i],cur);
if(c[i]) chkmax(cur,i);
} cur=0;
for(int i=n;i>n/2;i--){
chkmax(ans[i],cur);
if(c[n-i+1]) chkmax(cur,n-i+1);
}
for(int i=1;i<=n;i++)
if(s[i]==t[i]) ans[i]=best;
for(int i=1;i<=n;i++) cout<<ans[i]<<"\n";
return 0;
}
详细
Subtask #1:
score: 23
Accepted
Test #1:
score: 23
Accepted
time: 2ms
memory: 28272kb
input:
cbaababaabacbaababaabacbaabacbaababaabacbaaba dabbababbabaabbafabbgbaabfebaabzababbayaabcac
output:
0 0 0 0 0 0 6 6 6 6 6 6 6 6 6 6 6 17 17 17 17 17 17 17 17 17 17 17 6 6 6 6 6 6 6 6 6 6 6 0 0 0 3 0 1
result:
ok 45 numbers
Test #2:
score: 23
Accepted
time: 2ms
memory: 26160kb
input:
cbaababaabacbaabadbaababaabacbaabacbaaba aabwaxjbbabtalbabcasbabibbabaabbabaabiac
output:
3 0 0 0 0 0 6 6 6 6 6 6 6 6 6 6 6 23 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 0 0 0 0 0 1
result:
ok 40 numbers
Test #3:
score: 23
Accepted
time: 0ms
memory: 26220kb
input:
cadaabacabacabacabaabacabacadaabacabacaba bbbbbabtbabababalalbawababababbaoababebdc
output:
2 0 4 0 0 0 0 0 0 0 0 0 0 0 0 15 15 15 15 15 15 15 15 15 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 4 1
result:
ok 41 numbers
Test #4:
score: 23
Accepted
time: 0ms
memory: 26232kb
input:
dabacbaadcbaadabacbaadabecbaadcbaadabacbaadabacbaa ababaabbyaarbabfbvdbuaoaaaabbaaabbababaabbababqadd
output:
2 0 0 0 0 0 0 0 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 29 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 0 0 0 0 0 0 2 1
result:
ok 50 numbers
Test #5:
score: 23
Accepted
time: 0ms
memory: 28216kb
input:
edacbcacacbcaecbcacacbcadacbcacacbca sabaaabtbaaabaaalblbawaeabaaababoaae
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 0 0 0 0 0 0 0 0 0 0 0 1
result:
ok 36 numbers
Test #6:
score: 23
Accepted
time: 4ms
memory: 28212kb
input:
cbaababaabacbaabacbaabdbaabacbaabacbaaba aabbababbaoaabbxbaabbaqabbabltbpagaabcac
output:
3 0 0 0 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 0 0 0 3 0 1
result:
ok 40 numbers
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #7:
score: 0
Wrong Answer
time: 0ms
memory: 26132kb
input:
abacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacadcabbacabbacabcabbacababacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacadcabbacabbacaecabbacabacabbacabbacabcabbacabbacadcabbacabbacabcabbacababacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacad...
output:
27 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75...
result:
wrong answer 3139th numbers differ - expected: '717', found: '4623'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%