Submission #535110

#TimeUsernameProblemLanguageResultExecution timeMemory
535110__VariattoThree Friends (BOI14_friends)C++17
0 / 100
14 ms12904 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define ll long long const int MAX=2e5+10, P=313, mod=1e9+696969; int n; ll hasz[MAX], pot[MAX]; string s; ll fh(int a, int b){ return ((hasz[b]-(hasz[a-1]*pot[b-a+1])%mod)+mod)%mod; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); pot[0]=1; for(int i=1; i<=MAX-5; i++) pot[i]=(pot[i-1]*P)%mod; cin>>n>>s; if(n%2==0){ cout<<"NOT POSSIBLE\n"; return 0; } s='%'+s; for(int i=1; i<=n; i++) hasz[i]=((hasz[i-1]*P)%mod+(s[i]-'A'))%mod; int ile=0, wyn=0; for(int i=1; i<=n; i++){ if(i==n/2+1 && fh(i, n/2)==fh(n/2+2, n)) wyn=i, ile++; if(i<n/2+1){ ll l=fh(1, i-1), p=fh(i+1, n/2+1); ll caly=((l*pot[n/2+1-i-1+1])%mod+p)%mod; if(caly==fh(n/2+2, n)) wyn=i, ile++; } if(i>n/2+1){ ll l=fh(n/2+1, i-1), p=fh(i+1, n); ll caly=((l*pot[max(0, n-i-1+1)])%mod+p)%mod; if(caly==fh(1, n/2)) wyn=i, ile++; } } if(!ile) cout<<"NO POSSIBLE\n"; else if(ile>1) cout<<"NOT UNIQUE\n"; else{ int xd=0; for(int i=1; i<=n; i++){ if(i!=wyn){ cout<<s[i]; xd++; } if(xd==n/2) break; } cout<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...