QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#831848 | #8701. Border | wwjjrr_yohu | 23 | 10ms | 56248kb | C++14 | 1.8kb | 2024-12-25 17:22:31 | 2024-12-25 17:22:33 |
Judging History
answer
//mod!
//N=inf!
//long long!
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+5;
const long long mod1=1e9+7,mod2=1e9+9;
long long n,mi1[N],mi2[N],has1[N],has2[N],ans[N];
long long num[N];
vector<int> f[N];
string s,t;
pair<int,int> ask(int l,int r){
if(l>r) return {0,0};
int len=r-l+1;
return{(has1[r]-has1[l-1]*mi1[len]%mod1+mod1)%mod1,(has2[r]-has2[l-1]*mi2[len]%mod2+mod2)%mod2};
}
pair<int,int> ask1(int l,int r,int p){
if(l>r) return {0,0};
int len=r-l+1;
if(l>p||r<p){
return{(has1[r]-has1[l-1]*mi1[len]%mod1+mod1)%mod1,(has2[r]-has2[l-1]*mi2[len]%mod2+mod2)%mod2};
}
else{
return{(has1[r]-has1[l-1]*mi1[len]%mod1+(t[p]-s[p])*mi1[r-p]%mod1+2*mod1)%mod1,(has2[r]-has2[l-1]*mi2[len]%mod2+(t[p]-s[p])*mi2[r-p]%mod2+mod2)%mod2};
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>s>>t;
n=s.size();
s=" "+s;
t=" "+t;
mi1[0]=mi2[0]=1;
for(int i=1;i<=n;i++) mi1[i]=mi1[i-1]*131%mod1,mi2[i]=mi2[i-1]*131%mod2;
for(int i=1;i<=n;i++) has1[i]=has1[i-1]*131+s[i],has2[i]=has2[i-1]*131+s[i],has1[i]%=mod1,has2[i]%=mod2;
for(int i=1;i<n;i++) num[i]=max(num[i-1],0ll+i*(ask(1,i)==ask(n-i+1,n)));
// for(int i=1;i<=n;i++) cout<<num[i]<<" ";
// cout<<"\n";
for(int i=2;i<=n;i++){
if(ask(1,n-i+1)==ask(i,n)) continue;
int lp=0,rp=n-i+1,res,mid;
while(lp<=rp){
mid=lp+rp>>1;
if(ask(1,mid)==ask(i,i+mid-1)) lp=mid+1,res=mid;
else rp=mid-1;
}
// cout<<i<<" "<<res<<"\n";
int p=res+1,q=i+res;
if(ask1(1,n-i+1,p)==ask1(i,n,p)) ans[p]=max(ans[p],n-i+1);
if(ask1(1,n-i+1,q)==ask1(i,n,q)) ans[q]=max(ans[q],n-i+1);
}
for(int i=1;i<=n;i++){
if(t[i]==s[i]) ans[i]=num[n-1];
else ans[i]=max(ans[i],num[min(i-1ll,n-i)]);//和t无相交
}
for(int i=1;i<=n;i++) cout<<ans[i]<<"\n";
}
详细
Subtask #1:
score: 23
Accepted
Test #1:
score: 23
Accepted
time: 8ms
memory: 55584kb
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: 10ms
memory: 55924kb
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: 5ms
memory: 55616kb
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: 3ms
memory: 54984kb
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: 8ms
memory: 56248kb
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: 55372kb
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: 31
Accepted
time: 8ms
memory: 55484kb
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:
ok 4623 numbers
Test #8:
score: 0
Wrong Answer
time: 3ms
memory: 55396kb
input:
gcdcbcacacacbcacdcbcacaedcbcacacacbcacdcfcacacdcbcacaedcbcacacacbcacdcbcacacdcbcacacdcbcacacacbcacdcbcacaedcbcacacacbcacdcbcacacdcbcacacdcbcacacacbcacdcbcacaedcbcacacacbcacdcbcacacdcbcacagcdcbcacacacbcacdcbcacaedcbcacacacbcacdcbcacacdcbcacaedcbcacacacbcacdcbcacacdcbcacacdcbcacacacbcacdcbcacaedcbcaca...
output:
187 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1607th numbers differ - expected: '1845', found: '508'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%