제출 #240571

#제출 시각아이디문제언어결과실행 시간메모리
240571Goolakh세 명의 친구들 (BOI14_friends)C++17
0 / 100
115 ms34840 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("Os") #define F first #define S second #define pb push_back #define SZ(x) (ll)(x.size()) #define all(x) x.begin(),x.end() //#define mp make_pair typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll maxn=2e6+10, maxm=2e3+10, lg=22, mod=1e9+9, inf=1e18; const ll B=1e9+7; ll pw[maxn]; ll n,h[maxn]; string s; map<ll,bool> mp; ll mash(ll l,ll r){ if(l>r) return 0; return (h[r]-(h[l-1]*pw[r-l+1]%mod)+mod)%mod; } int main(){ ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); pw[0]=1; for(int i=1;i<maxn;i++) pw[i]=pw[i-1]*B%mod; cin>>n>>s; if(n%2==0) return cout<<"NOT POSSIBLE",0; for(int i=0;i<n;i++) h[i]=(h[i-1]*B+s[i]-'A')%mod; ll mid=n/2,we=-1; for(int i=0;i<mid;i++){ ll m1=(mash(0,i-1)*pw[max(mid-i,0ll)]+mash(i+1,mid))%mod; ll m2=mash(mid+1,n-1); if(m1==m2) mp[m1]=1, we=i; } ll m1=mash(0,mid-1); ll m2=mash(mid+1,n-1); if(m1==m2) mp[m1]=1, we=mid; for(int i=mid+1;i<n;i++){ ll m1=mash(0,mid-1); ll m2=(mash(mid,i-1)*pw[n-i-1]+mash(i+1,n-1))%mod; if(m1==m2) mp[m1]=1, we=i; } if(mp.empty()) cout<<"NOT POSSIBLE"; else if(SZ(mp)==1){for(int i=0;mid && i<n;i++)if(i!=we) cout<<s[i], mid--;} else cout<<"NOT UNIQUE"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...