이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define maxN 200005
using namespace std;
string s;
unsigned long long h[maxN],p[maxN],t,tmp,pom,n,i,ans;
vector <unsigned long long> v;
int main()
{
cin>>n;
cin>>s;
if(n%2==0) {cout<<"NOT POSSIBLE"<<endl; return 0;}
h[0]=s[0]-'A'+1;
p[0]=1;
for(i=1;i<maxN;i++){p[i]=27*p[i-1];}
return 0;
t=(n-1)/2;
for(i=0;i<n;i++){
if(i<t){
if(i>0) tmp=p[t+1]*(h[i-1])+p[t]*(h[t]-h[i]);
else tmp=p[t]*(h[t]-h[0]);
pom=h[n-1]-h[t];
if(tmp==pom && (v.empty() || v[0]!=tmp)) {v.push_back(tmp); ans=i;}
}
else{
if(i<n-1) tmp=27*(h[i-1]-h[t-1])+(h[n-1]-h[i]);
else tmp=27*(h[n-2]-h[t-1]);
pom=p[t+1]*h[t-1];
if(tmp==pom && (v.empty() || v[0]!=tmp)) {v.push_back(tmp); ans=i;}
}
if(v.size()>1) {cout<<"NOT UNIQUE"<<endl; return 0;}
}
if(v.size()==0) {cout<<"NOT POSSIBLE"<<endl; return 0;}
for(i=0;i<t;i++){if(ans!=i) cout<<s[i];}
if(ans<t) cout<<s[t];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |