QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#831891 | #8701. Border | thomas0702 | 0 | 1ms | 6012kb | C++14 | 2.1kb | 2024-12-25 17:47:19 | 2024-12-25 17:47:19 |
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lll __int128
#define db double
#define ld long double
#define eps 1e-8
#define fir first
#define sec second
#define pb push_back
using namespace std;
void rd(){}
template<typename T,typename... U> void rd(T &x,U&... arg){
x=0;int f=1,c=getchar();
while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
x*=f;rd(arg...);
}
void rds(char *s){
int c=getchar();
while(c<'a'||c>'z') c=getchar();
while(c>='a'&&c<='z') *s=(char)c,s++,c=getchar();
*s='\0';
}
/*枚举border的长度 分成两种
(1)本来就是S的border 容易贡献到答案中
(2)只需要修改一个字符就变成border 贡献到对应位置
对(2)的判断可以哈希 也可以exkmp*/
inline bool chkmax(int &x,int y){return x<y&&(x=y,1);}
const int maxn=2e6+5;
const char C='a';
int N,z1[maxn],z2[maxn],a[maxn],n,border,ok[maxn][26];
char s[maxn],t[maxn];
void Z(char *s,int *z){
int n=z[1]=(int)strlen(s+1);
while(2+z[2]<=n&&s[1+z[2]]==s[2+z[2]]) z[2]++;
for(int i=3,l=2,r=z[2]+1;i<=n;i++){
z[i]=max(0,min(r-i+1,z[i-l+1]));
while(i+z[i]<=n&&s[1+z[i]]==s[i+z[i]]) z[i]++;
if(i+z[i]-1>r) l=i,r=i+z[i]-1;
}
}
int main(){
rds(s+1),rds(t+1),N=(int)strlen(s+1);
reverse(s+1,s+N+1),Z(s,z2),reverse(z2+1,z2+N+1);
reverse(s+1,s+N+1),Z(s,z1);
// for(int i=1;i<=N;i++) printf("%d ",z1[i]);puts("");
// for(int i=1;i<=N;i++) printf("%d");
for(int i=1;i<N;i++){
int x=z1[N-i+1],y=z2[i];
// printf("i = %d, x = %d, y = %d\n",i,x,y);
if(x==i){
a[++n]=i;
chkmax(border,i);
continue;
}
if(x+y==i-1){
chkmax(ok[x+1][s[N-i+1+x]-C],i);
chkmax(ok[N-i+1+x][s[x+1]-C],i);
}else if(2*i-1==N){
bool flag=s[1]==s[N];
for(int j=2;j<i;j++) flag&=s[j]==s[N-i+j];
if(flag) chkmax(ok[i][s[1]-C],i);
}
}
for(int i=1,j=0;i<=N;i++){
if(s[i]==t[i]){printf("%d\n",border);continue;}
while(j<n&&a[j+1]<i) j++;
while(j&&a[j]>N-i) j--;
int Max=a[j];
for(int j=0;j<26;j++) chkmax(Max,ok[i][j]);
printf("%d\n",Max);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6012kb
input:
cbaababaabacbaababaabacbaabacbaababaabacbaaba dabbababbabaabbafabbgbaabfebaabzababbayaabcac
output:
3 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:
wrong answer 1st numbers differ - expected: '0', found: '3'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%