QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#830628 | #8701. Border | LYLAKIOI | 0 | 2ms | 10300kb | C++14 | 2.7kb | 2024-12-24 21:09:09 | 2024-12-24 21:09:20 |
Judging History
answer
#include<bits/stdc++.h>
#define up(i,l,r) for(int i=(l);i<=(r);++i)
#define down(i,l,r) for(int i=(l);i>=(r);--i)
#define pi pair<int,int>
#define p1 first
#define p2 second
#define m_p make_pair
#define p_b push_back
#define ppc __builtin_popcount
typedef long long ll;
typedef unsigned int uint;
using namespace std;
const int inf=1e8+1;
const int maxn=2e6+10;
const int base1=97,mod1=998244353;
const int base2=131,mod2=1011451423;
inline ll read(){
ll x=0;short t=1;char ch=getchar();if(ch==-1)exit(0);
while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*t;
}
int n,h[maxn],pw1[maxn],pw2[maxn];
string s,t;
int res[maxn][26];
struct Hash {
int s1,s2,len;
}d[maxn];
Hash operator+(Hash a,Hash b){
Hash res;
res.s1=(a.s1*1ll*pw1[b.len]%mod1+b.s1)%mod1;
res.s2=(a.s2*1ll*pw2[b.len]%mod2+b.s2)%mod2;
res.len=a.len+b.len;
return res;
}
Hash operator-(Hash a,Hash b){
Hash res;
res.len=a.len-b.len;
res.s1=(a.s1-b.s1*1ll*pw1[res.len]%mod1+mod1)%mod1;
res.s2=(a.s2-b.s2*1ll*pw2[res.len]%mod2+mod2)%mod2;
return res;
}
Hash g(int l,int r,int p){
if(r<p||l>p)return d[r]-d[l-1];
return (d[p-1]-d[l-1])+(Hash){t[p]-'a'+1,t[p]-'a'+1,1}+(d[r]-d[p]);
}
void exk(){
int l=0,r=0;
up(i,2,n){
if(i<=r)h[i]=min(r-i+1,h[i-l+1]);
while(i+h[i]<=n&&s[i+h[i]]==s[1+h[i]])++h[i];
if(i+h[i]-1>=r)r=i+h[i]-1,l=i;
}
//printf("h:");up(i,1,n)printf("%d ",h[i]);printf("\n");
}
bool chk(int x,int k){return !(x>=n-k+1||x<=k);}
bool operator==(Hash a,Hash b){return a.s1==b.s1&&a.s2==b.s2&&a.len==b.len;}
void slv(){
cin>>s>>t;n=s.size();s=" "+s,t=" "+t;exk();
pw1[0]=pw2[0]=1;up(i,1,n)pw1[i]=pw1[i-1]*1ll*base1%mod1,pw2[i]=pw2[i-1]*1ll*base2%mod2;
up(i,1,n)d[i]=d[i-1]+(Hash){s[i]-'a'+1,s[i]-'a'+1,1};
vector<int>P;
down(i,n,2){
if(h[i]==n-i+1)P.p_b(n-i+1);
else {
int p=i+h[i];
if(h[p+1]==n-p)res[p][s[p-i+1]-'a']=res[h[i]+1][s[p]-'a']=n-i+1;
}
}
up(i,1,n){
if(s[i]==t[i])printf("%d\n",(P.size()?P.back():0));
else {
int s=res[i][t[i]-'a'];
if((!P.empty())&&chk(i,P[0])){
int l=0,r=P.size();
while(l+1<r){
int mid=l+r>>1;
if(chk(i,P[mid]))l=mid;
else r=mid;
}s=max(s,P[l]);
}
if(g(1,n-i+1,i)==g(i,n,i)&&i!=1)s=max(s,n-i+1);
printf("%d\n",s);
}
}
}
int main(){
//freopen("1.in","r",stdin),freopen("1.out","w",stdout);
slv();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<"s\n";
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 23
Accepted
time: 2ms
memory: 10300kb
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: 0
Wrong Answer
time: 0ms
memory: 10068kb
input:
cbaababaabacbaabadbaababaabacbaabacbaaba aabwaxjbbabtalbabcasbabibbabaabbabaabiac
output:
7 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:
wrong answer 1st numbers differ - expected: '3', found: '7'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%