QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#833464#8701. BorderQyun0 2ms12052kbC++142.1kb2024-12-26 20:07:222024-12-26 20:07:23

Judging History

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

  • [2024-12-26 20:07:23]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:12052kb
  • [2024-12-26 20:07:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int ll

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define fi first
#define se second
#define ls o<<1
#define rs o<<1|1

bool __M1;
int __st=clock();

const int maxn=2e6+10;
const ull base=13331;

int n;
char s[maxn],t[maxn];
ull h[maxn],pw[maxn];

int ans[maxn];

struct Exkmp
{
	int z[maxn];
	void init(bool op)
	{
		if(op)reverse(s+1,s+1+n);
		
		for(int i=2,p=0,r=0;i<=n;++i)
		{
			if(i<r)z[i]=min(z[i-p+1],r-i+1);
			while(s[1+z[i]]==s[i+z[i]])++z[i];
			if(i+z[i]-1>r)p=i,r=i+z[i]-1;
		}
		
		if(op)reverse(s+1,s+1+n),reverse(z+1,z+1+n);
	}	
	
	void put(){for(int i=1;i<=n;++i)cout<<z[i]<<" ";cout<<"\n";}
}k[2];

ull get(int l,int r){return h[r]-h[l-1]*pw[r-l+1];}

bool check(int l,int r,int L,int R){return get(l,r)==get(L,R);}

bool __M2;

signed main()
{
//	freopen("","r",stdin);
//	freopen("","w",stdout);

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	cin>>s+1>>t+1;n=strlen(s+1);
	
	k[0].init(0),k[1].init(1);	
	
//	k[0].put();
//	k[1].put();
	
	
	int B=0;
	for(int i=1;i<=n;++i)if(k[0].z[i]+i-1==n){B=k[0].z[i];break;}
	
//	cout<<"::"<<B<<"\n";
	for(int i=1;i<=n;++i)
	{
		ans[i]=min({i-1,n-i,B});
		if(s[i]==t[i])ans[i]=B;
	}
	
	for(int i=1;i<=n;++i)h[i]=h[i-1]*base+s[i]-'a';
	pw[0]=1;
	for(int i=1;i<=n;++i)pw[i]=pw[i-1]*base;
	
	for(int L=1;L<=n;++L)
	{
		int lcp=k[0].z[n-L+1],lsp=k[1].z[L],p1=L-lsp,p2=(n-L+1)+lcp;
		if(lcp+lsp+1==L)
		{
			if(t[p1]==s[p2])ans[p1]=max(ans[p1],L);
			if(s[p1]==t[p2])ans[p2]=max(ans[p2],L);
		}
		else if(2*L>n and p1==p2)
		{
			int u=1+lcp,v=n-lsp;
//			cout<<L<<":"<<p1<<"\n";
//			cout<<"_"<<u<<" "<<v<<"\n";
//			cout<<"["<<u+1<<","<<p1-1<<"]["<<p1+1<<","<<v-1<<"]\n";
			if(s[u]==s[v] and check(u+1,p1-1,p1+1,v-1))
			{
				if(t[p1]==s[u])ans[p1]=max(ans[p1],L);
			}
		}
	}
	
	for(int i=1;i<=n;++i)cout<<ans[i]<<"\n";
	
	cerr<<(clock()-__st)<<"ms\n";
	cerr<<(&__M1-&__M2)/1024/1024<<"MB\n";

	cout.flush(),fclose(stdin),fclose(stdout);

	return 0;
}


詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 12052kb

input:

cbaababaabacbaababaabacbaabacbaababaabacbaaba
dabbababbabaabbafabbgbaabfebaabzababbayaabcac

output:

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
17
17
17
17
17
17
17
17
17
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
3
1
1

result:

wrong answer 2nd numbers differ - expected: '0', found: '1'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%