This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<memory.h>
#include<string>
using namespace std;
const int mod=1e9+7;
int len;
string s,a,b;
int dp[1000002][2];
int f(int st,bool use)
{
if(~dp[st][use]) return dp[st][use];
if(st==b.size())
{
if(!use) return dp[st][use]=1;
else return dp[st][use]=(a[st]==b[st-1]);
}
int res=use?0:f(st+1,true);
if(a[st]!=b[st-use]) return dp[st][use]=res;
else return dp[st][use]=f(st+1,use)+res;
}
int main()
{
cin>>len>>s;
if(!(len&1) || len==1) { cout<<"NOT POSSIBLE"; return 0; }
if(s.substr(0,len/2)==s.substr(len/2+1,len/2)) { cout<<s.substr(0,len/2); return 0; }
a=s.substr(0,len/2+1);
b=s.substr(len/2+1,len/2);
memset(dp,-1,sizeof(dp));
int cnt1=f(0,false);
a=s.substr(len/2,len/2+1);
b=s.substr(0,len/2);
memset(dp,-1,sizeof(dp));
int cnt2=f(0,false);
if(cnt1+cnt2==0) cout<<"NOT POSSIBLE";
else if(cnt1 && cnt2) cout<<"NOT UNIQUE";
else cout<<(cnt1?s.substr(len/2+1,len/2):s.substr(0,len/2));
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |