제출 #240566

#제출 시각아이디문제언어결과실행 시간메모리
240566GoolakhThree Friends (BOI14_friends)C++17
0 / 100
21 ms12956 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=2e5+10, maxm=2e3+10, lg=22, mod=998244353, inf=1e18; const ll B=619; ll pw[maxn]; ll n,h[maxn]; string s; 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\n",0; for(int i=0;i<n;i++) h[i]=(h[i-1]*B+s[i]-'A')%mod; ll tt=0,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) tt++, we=i; } if(mash(0,mid-1)==mash(mid+1,n-1)) tt++, 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) tt++, we=i; } if(tt==0) cout<<"NOT POSSIBLE"; if(tt==1)for(int i=0;mid && i<n;i++)if(i!=we) cout<<s[i], mid--; if(tt>1) cout<<"NOT UNIQUE"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...