QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#606280#8701. BorderMirasycle23 3ms28288kbC++141.6kb2024-10-03 00:13:402024-10-03 00:13:41

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 00:13:41]
  • 评测
  • 测评结果:23
  • 用时:3ms
  • 内存:28288kb
  • [2024-10-03 00:13:40]
  • 提交

answer

#include<bits/stdc++.h>
#define push_back emplace_back
#define fi first
#define se second
#define make_pair mp
using namespace std;
typedef long long ll;
const int maxn=4e6+10;
const int mod=1e9+7;
char s[maxn],t[maxn];
ll p[maxn],h[maxn]; int pos;
int z[maxn],ans[maxn],c[maxn],n;
vector<pair<int,int> > vec;
int id(char cha){ return cha-'a'+1; }
ll gethash(int l,int r){
	if(l>r) return 0;
	if(pos>r||pos<l) return (mod+h[r]-h[l-1]*p[r-l+1]%mod)%mod;
	else return (gethash(pos+1,r)+1ll*id(t[pos])*p[r-pos]%mod+1ll*gethash(l,pos-1)*p[r-pos+1]%mod)%mod;
}
bool chk(int l1,int r1,int l2,int r2){ return gethash(l1,r1)==gethash(l2,r2); }
void chkmax(int &x,int y){ x=x>=y?x:y; }
void init(){
	n=strlen(s+1); p[0]=1;
	for(int i=1;i<=n;i++) p[i]=p[i-1]*131%mod;
	for(int i=1;i<=n;i++) h[i]=(h[i-1]*131%mod+id(s[i]))%mod;
}
int main(){
	cin>>(s+1)>>(t+1); init();
	z[1]=n; int l=0,r=0;
	for(int i=2;i<=n;i++){
		z[i]=i>r?0:min(r-i+1,z[i-l+1]);
		while(s[1+z[i]]==s[i+z[i]]&&i+z[i]<=n) z[i]++;
		if(i+z[i]-1>r) r=i+z[l=i]-1;
	}
	int best=0; memset(ans,0,sizeof(ans));
	for(int i=1;i<=n;i++)
		if(i+z[i]>n) chkmax(best,n-i+1),c[n-i+1]++;
		else{
			pos=i+z[i]; if(chk(1,n-i+1,i,n)) chkmax(ans[pos],n-i+1);
			pos=z[i]+1; if(chk(1,n-i+1,i,n)) chkmax(ans[pos],n-i+1);
		}
	int cur=0;
	for(int i=1;i<=n/2;i++){
		chkmax(ans[i],cur); 
		if(c[i]) chkmax(cur,i);
	} cur=0;
	for(int i=n;i>n/2;i--){
		chkmax(ans[i],cur); 
		if(c[n-i+1]) chkmax(cur,n-i+1);
	}
	for(int i=1;i<=n;i++)
		if(s[i]==t[i]) ans[i]=best;
	for(int i=1;i<=n;i++) cout<<ans[i]<<"\n";
	return 0;
}

詳細信息

Subtask #1:

score: 23
Accepted

Test #1:

score: 23
Accepted
time: 0ms
memory: 26244kb

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: 28224kb

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: 3ms
memory: 26188kb

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: 3ms
memory: 28240kb

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: 28288kb

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: 3ms
memory: 28156kb

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: 0ms
memory: 28248kb

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 3139th numbers differ - expected: '717', found: '4623'

Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%