Submission #18634

#TimeUsernameProblemLanguageResultExecution timeMemory
18634mindolThree Friends (BOI14_friends)C++14
100 / 100
144 ms92524 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...