QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#853035 | #8701. Border | ChiFAN | 23 | 5ms | 3952kb | C++14 | 3.6kb | 2025-01-11 15:22:49 | 2025-01-11 15:22:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
const int maxn = 2e6+114;
mt19937 rd(time(0));
int to[26];
int qpow(int a,int b){
if(b==0) return 1;
if(b==1) return a;
int res=qpow(a,b/2);
res=res*res%mod;
if(b%2==1) res=res*a%mod;
return res;
}
vector<int> solve(string s,string t){
vector<int> S,T;
int n=s.size();
S.resize(n+1),T.resize(n+1);
for(int i=1;i<=n;i++) S[i]=to[s[i-1]-'a'],T[i]=to[t[i-1]-'a'];
vector<int> v1,v2,v3;
v1.resize(n+1);
v2.resize(n+1);
v3.resize(n+1);
vector<int> ans;
ans.resize(n+1);
for(int i=1;i<=n;i++){
v1[i]=(v1[i-1]+S[i])%mod;
v2[i]=(v2[i-1]+S[i]*S[i]%mod)%mod;
v3[i]=(v3[i-1]+S[i]*i%mod)%mod;
}
vector<int> suf;
suf.resize(n+1);
for(int i=1;i<n;i++){
vector<int> pos;
bool flag=true;
for(int j=2;i*(j-1)+1<=n;j++){
if(pos.size()==2){
flag=false;
break;
}
int L=(j-1)*i+1,R=j*i;
int l=1,r=i;
if(R>n){
int c=R-n;
R-=c,r-=c;
}
//cout<<i<<' '<<l<<' '<<r<<' '<<L<<' '<<R<<'\n';
if((v3[r]+mod-v3[l-1])%mod==((v3[R]+mod-v3[L-1])%mod+mod-(L-l)*((v1[R]+mod-v1[L-1])%mod)%mod)%mod) continue;
else{
int c1=(v2[r]+v2[L-1]+2*mod-v2[l-1]-v2[R])%mod,c2=(v1[r]+v1[L-1]+2*mod-v1[l-1]-v1[R])%mod;
c1=c1*qpow(c2,mod-2)%mod;
int x=(c1+c2)*((mod+1)/2)%mod;
int y=(c1+mod-c2)%mod*((mod+1)/2)%mod;
int c3=(v3[R]+mod-v3[L-1])%mod;
c3=(c3+mod-(L-l)*((v1[R]+mod-v1[L-1])%mod)%mod)%mod;
int pd=((v3[r]+mod-v3[l-1])%mod+mod-c3)%mod;
int p=pd*qpow((x+mod-y)%mod,mod-2)%mod;
if(p<1||p>n){
flag=false;
break;
}
if(S[p]!=x){
flag=false;
break;
}
if(p+(L-l)>n){
flag=false;
break;
}
if(S[p+(L-l)]!=y){
flag=false;
break;
}
if(pd!=p*((x+mod-y)%mod)%mod){
flag=false;
break;
}
if(T[p+(L-l)]!=x){
flag=false;
break;
}
pos.push_back(p+(L-l));
}
}
if(flag==false) continue;
if(pos.size()==1){
ans[pos[0]]=max(ans[pos[0]],n-i);
}else if(pos.size()==0&&i*2>n){
suf[i]=max(suf[i],n-i);
}
}
for(int i=n-1;i>=1;i--) suf[i]=max(suf[i],suf[i+1]);
for(int i=1;i<=n;i++) ans[i]=max(ans[i],suf[max(i,n-i+1)]);
return ans;
}
signed main(){
for(int i=0;i<26;i++) to[i]=rd()%mod;
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
string s,t;
cin>>s>>t;
vector<int> ans=solve(s,t);
reverse(s.begin(),s.end());
reverse(t.begin(),t.end());
vector<int> oth=solve(s,t);
reverse(oth.begin(),oth.end());
vector<int> nxt;
nxt.resize(s.size());
nxt[0]=-1;
for(int i=1;i<s.size();i++){
int z=nxt[i-1];
while(s[z+1]!=s[i]&&z>-1) z=nxt[z];
if(s[z+1]==s[i]) nxt[i]=z;
}
for(int i=0;i<s.size();i++){
if(s[i]==t[i]) cout<<nxt[s.size()-1]<<'\n';
else cout<<max(ans[i+1],oth[i])<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 23
Accepted
Test #1:
score: 23
Accepted
time: 0ms
memory: 3652kb
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: 0ms
memory: 3652kb
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: 3952kb
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: 3720kb
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: 3716kb
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: 0ms
memory: 3720kb
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: 5ms
memory: 3852kb
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 1485th numbers differ - expected: '717', found: '0'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%