Submission #314538

#TimeUsernameProblemLanguageResultExecution timeMemory
314538FidiskThree Friends (BOI14_friends)C++14
100 / 100
110 ms52340 KiB
#include <bits/stdc++.h> using namespace std; #define oo 1e9 #define fi first #define se second #define sp(iiii) setprecision(iiii) #define IO ios_base::sync_with_stdio(false); cin.tie(0) #define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa)) #define cntbit(xxxx) __builtin_popcount(xxxx) #define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1) typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<pair<int,int>,int> piii; typedef pair<long long,long long> pll; typedef pair<pair<long long,long long>,long long> plll; const ll mod=1e9+7; const ll base=361; string s; ll n,i,hashs[5000009],po[5000009],pos,type[5000009],cur; bool ok; ll get(ll x,ll y) { if (x>y) { return 0; } return (hashs[y]-hashs[x-1]*po[y-x+1]+mod*mod)%mod; } int main(){ IO; //freopen("threefriend.inp","r",stdin); //freopen("threefriend.out","w",stdout); cin>>n; cin>>s; //cout<<n<<'\n'; //cout<<s<<'\n'; if (n%2==0) { cout<<"NOT POSSIBLE"; return 0; } s=" "+s; po[0]=1; for (i=1;i<=n;i++) { hashs[i]=(hashs[i-1]*base+s[i])%mod; po[i]=(po[i-1]*base)%mod; } for (i=1;i<=n;i++) { if (s[i]!=s[i-1]) { cur++; } type[i]=cur; } for (i=1;i<=n;i++) { if (i<=((n+1)/2)) { //cout<<1<<' '<<i-1<<' '<<(n+1)/2+1<<' '<<(n+1)/2+i-1<<' '<<i+1<<' '<<(n+1)/2<<' '<<(n+1)/2+i<<' '<<n<<'\n'; if (get(1,i-1)==get((n+1)/2+1,(n+1)/2+i-1)&&get(i+1,(n+1)/2)==get((n+1)/2+i,n)) { if (ok&&type[i]!=type[pos]) { cout<<"NOT UNIQUE"; return 0; } else { ok=true; pos=i; } } } else { //cout<<1<<' '<<i-(n+1)/2<<' '<<(n+1)/2<<' '<<i-1<<' '<<i-(n+1)/2+1<<' '<<(n+1)/2-1<<' '<<i+1<<' '<<n<<'\n'; if (get(1,i-(n+1)/2)==get((n+1)/2,i-1)&&get(i-(n+1)/2+1,(n+1)/2-1)==get(i+1,n)) { if (ok&&type[i]!=type[pos]) { cout<<"NOT UNIQUE"; return 0; } else { ok=true; pos=i; } } } } if (!ok) { cout<<"NOT POSSIBLE"; return 0; } if (pos<=(n+1)/2) { for (i=(n+3)/2;i<=n;i++) { cout<<s[i]; } } else { for (i=1;i<(n+1)/2;i++) { cout<<s[i]; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...