QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#853488 | #8701. Border | ChiFAN | 0 | 16ms | 144284kb | C++14 | 3.9kb | 2025-01-11 17:09:50 | 2025-01-11 17:09:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
const int Mod = 998244353;
const int base = 3;
const int maxn = 2e6+114;
int _pow[maxn];
mt19937 rd(time(0));
int to[26];
int ch[26];
inline int qpow(int a,int b){
int res=1;
for(int i=0;i<33;i++){
if((1ll<<i)&b) res=res*a%mod;
a=a*a%mod;
}
return res;
}
vector<int> solve(string s,string t){
int n=s.size();
array<int,maxn> S,T,P;
for(int i=1;i<=n;i++) S[i]=to[s[i-1]-'a'],T[i]=to[t[i-1]-'a'],P[i]=ch[s[i-1]-'a'];
array<int,maxn> v1,v2,v3,v4;
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;
v4[i]=(v4[i-1]+P[i]*_pow[i]%Mod)%Mod;
}
array<int,maxn> suf;
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;
}
if((v4[r]+Mod-v4[l-1])%Mod*_pow[L-l]%Mod==(v4[R]+Mod-v4[L-1])%mod&&(v1[r]+mod-v1[l-1])%mod==(v1[R]+mod-v1[L-1])%mod&&(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*((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,ch[i]=rd()%Mod;
_pow[0]=1;
for(int i=1;i<maxn;i++) _pow[i]=_pow[i-1]*base%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());
reverse(s.begin(),s.end());
reverse(t.begin(),t.end());
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]) z++;
nxt[i]=z;
}
for(int i=0;i<s.size();i++){
if(s[i]==t[i]) cout<<nxt[s.size()-1]+1<<'\n';
else cout<<max(ans[i+1],oth[i])<<'\n';
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 16ms
memory: 144284kb
input:
cbaababaabacbaababaabacbaabacbaababaabacbaaba dabbababbabaabbafabbgbaabfebaabzababbayaabcac
output:
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 3 0 1
result:
wrong answer 7th numbers differ - expected: '6', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%