QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#834581#8701. BorderIshar-zdl0 15ms103092kbC++142.3kb2024-12-27 20:40:052024-12-27 20:40:05

Judging History

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

  • [2024-12-27 20:40:05]
  • 评测
  • 测评结果:0
  • 用时:15ms
  • 内存:103092kb
  • [2024-12-27 20:40:05]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii std::pair<int,int>
#define eb emplace_back
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
std::mt19937_64 myrand(std::chrono::high_resolution_clock::now().time_since_epoch().count());
inline int R(int n){return myrand()%n+1;}
inline int read(){char ch=getchar();int x=0,f=1;for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);return x*f;}
template<typename T> inline void Min(T&x,T y){if(x>y)x=y;}
template<typename T> inline void Max(T&x,T y){if(x<y)x=y;}
const int N=2e6+10,mod=1000000241,P=1333331;
int n,hs[N],p[N],border,ans[N];
char s[N],t[N];
std::vector<int> v1[N],v2[N];
inline int gethash(int l,int r){
	return ((hs[r]-hs[l-1]*p[r-l+1]%mod)+mod)%mod;
}
inline int LCP(int x){
	int l=1,r=n-x+1,res=0;while(l<=r){
		int mid=l+r>>1;if(gethash(1,mid)==gethash(x,x+mid-1))res=mid,l=mid+1;
		else r=mid-1;
	}return res;
}
inline int LCS(int x){
	int l=1,r=x,res=0;while(l<=r){
		int mid=l+r>>1;if(gethash(x-mid+1,x)==gethash(n-mid+1,n))res=mid,l=mid+1;
		else r=mid-1;
	}return res;
}
signed main(){
    // freopen("in.in","r",stdin);freopen("out.out","w",stdout);
    std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
    std::cin>>s+1>>t+1;n=strlen(s+1);
    p[0]=1;for(int i=1;i<=n;++i)p[i]=p[i-1]*P%mod,hs[i]=(hs[i-1]*P+s[i])%mod;
    // for(int i=1;i<=n;++i)std::cout<<hs[i]<<' ';std::cout<<'\n';
    // for(int i=1;i<=n;++i)std::
    // std::cout<<gethash(1,4)<<' '<<'\n';z
    for(int i=1;i<n;++i){
    	if(gethash(1,i)==gethash(n-i+1,n)){
    		Max(border,i);
    		if(i+1<=n-i)v1[i+1].eb(i),v2[n-i].eb(i);
    		continue;
    	}
    	int lcp=LCP(n-i+1),lcs=LCS(i);
    	if(i*2==n+1){
    		auto zc=s[i];s[i]=t[i];
    		bool pd=1;
    		for(int j=1;j<=i;++j)pd&=s[j]==s[j+i-1];
    		s[i]=zc;if(pd)Max(ans[i],i);
    	}
    	if(lcp+lcs==i-1){
    		if(s[lcp+1]==t[n-lcs])Max(ans[n-lcs],i);
    		if(t[lcp+1]==s[n-lcs])Max(ans[lcp+1],i);
    	}
    }
    std::multiset<int> set;
    for(int i=1;i<=n;++i){
    	if(t[i]==s[i])Max(ans[i],border);
    	for(int x:v1[i])set.insert(x);
    	if(set.size())Max(ans[i],*set.rbegin());
    	for(int x:v2[i])set.erase(set.lower_bound(x));
    	std::cout<<ans[i]<<'\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 23
Accepted
time: 15ms
memory: 103092kb

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

input:

cbaababaabacbaabadbaababaabacbaabacbaaba
aabwaxjbbabtalbabcasbabibbabaabbabaabiac

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
0
0
1

result:

wrong answer 18th numbers differ - expected: '23', found: '6'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%