이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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=998244353, inf=1e18;
const ll B=619;
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\n",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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |