제출 #1331075

#제출 시각아이디문제언어결과실행 시간메모리
1331075boclobanchat세 명의 친구들 (BOI14_friends)C++20
100 / 100
80 ms34768 KiB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e6+67;
const long long mod=1e9+7;
long long H[MAXN],pw[MAXN];
long long get(int l,int r)
{
	return (H[r]-(__int128)H[l-1]*pw[r-l+1]%mod+mod)%mod;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    string s;
    cin>>n>>s;
    if(n%2==0) return cout<<"NOT POSSIBLE",0;
    s=' '+s,pw[0]=1;
    for(int i=1;i<=n;i++) pw[i]=pw[i-1]*31%mod,H[i]=(H[i-1]*31+s[i]-'A'+1)%mod;
    int ans=-1;
    long long h=-1;
    for(int i=1;i<=n;i++) if(i<n/2+1)
	{
		if(((__int128)get(1,i-1)*pw[n/2+1-i]+get(i+1,n/2+1))%mod==get(n/2+2,n))
    	{
    		ans=i;
    		if(h==-1) h=get(n/2+2,n);
    		else if(h!=get(n/2+2,n)) h=-2;
		}
	}
	else
	{
		if(get(1,n/2)==((__int128)get(n/2+1,i-1)*pw[n-i]+get(i+1,n))%mod)
		{
			ans=i;
    		if(h==-1) h=get(1,n/2);
    		else if(h!=get(1,n/2)) h=-2;
		}
	}
	if(h==-1) cout<<"NOT POSSIBLE";
	else if(h==-2) cout<<"NOT UNIQUE";
	else if(ans<n/2+1)
	{
		for(int i=n/2+2;i<=n;i++) cout<<s[i];
	}
	else
	{
		for(int i=1;i<=n/2;i++) cout<<s[i];
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...