QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#834364 | #8701. Border | xyin | 23 | 1ms | 10108kb | C++17 | 1.8kb | 2024-12-27 16:06:57 | 2024-12-27 16:06:58 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
#define pp pop_back
#define ls p<<1
#define rs p<<1|1
#define pb push_back
#define mk make_pair
#define pai pair<int,int>
using namespace std;
const int maxn=1e6+5;
// const int INF=1e18;
const int base=100411;
const int mod=1e9+0411;
typedef unsigned long long ull;
int read(int x=0,bool f=1,char c=0){
while (!isdigit(c=getchar())) f=c^45;
while (isdigit(c))
x=(x<<1)+(x<<3)+(c^48),c=getchar();
return f?x:-x;
}
int n,ans[maxn],o,tag[maxn];
char s[maxn],t[maxn];
int P[maxn],ha[maxn],las;
int get(int l,int r){
return (ha[r]-ha[l-1]*P[r-l+1]%mod+mod)%mod;
}
int bin_search(int l,int r,int t){
while (l<r){
int mid=(l+r)>>1;
if (get(1,mid)!=get(t,t+mid-1)) r=mid;
else l=mid+1;
}
return l;
}
bool check(int len,int o){
int t1=get(1,len),t2=get(n-len+1,n);
if (o>=1&&o<=len) t1=(t1-s[o]*P[len-o]%mod+t[o]*P[len-o]%mod+mod)%mod;
if (o>=n-len+1&&o<=n) t2=(t2-s[o]*P[n-o]%mod+t[o]*P[n-o]%mod+mod)%mod;
return t1==t2;
}
signed main(){
scanf("%s%s",s+1,t+1);
n=strlen(s+1);P[0]=1,ha[0]=1;
for (int i=1;i<=n;i++)
P[i]=P[i-1]*base%mod,
ha[i]=(ha[i-1]*base+s[i])%mod;
for (int len=1;len<=n;len++){
if (get(1,len)==get(n-len+1,n))
{tag[len]=1;o=len;continue;}
int t=bin_search(1,len,n-len+1);
if (check(len,t)) ans[t]=max(ans[t],len);
if (check(len,n-len+t))
ans[n-len+t]=max(ans[n-len+t],len);
}
for (int i=1;i<=(n+1)/2;i++){
if (s[i]==t[i]) ans[i]=o;
ans[i]=max(ans[i],las);
ans[n-i+1]=max(ans[n-i+1],las);
if (tag[i]) las=i;
}
for (int i=1;i<=n;i++)
printf("%lld\n",ans[i]);
}
详细
Subtask #1:
score: 23
Accepted
Test #1:
score: 23
Accepted
time: 0ms
memory: 10044kb
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: 1ms
memory: 9996kb
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: 1ms
memory: 9972kb
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: 1ms
memory: 9960kb
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: 1ms
memory: 9972kb
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: 1ms
memory: 10040kb
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: 0ms
memory: 10108kb
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: 0ms
memory: 9968kb
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 516th numbers differ - expected: '508', found: '3182'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%