# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
27460 | TAMREF | Three Friends (BOI14_friends) | C++11 | 6 ms | 3988 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int mx=2e6+10;
char S[mx];
int N,h;
void input(){
scanf("%d\n",&N);
fgets(S,mx-4,stdin);
S[N]=0;
if(!(N&1)) exit(0&puts("NOT POSSIBLE"));
h=(N-1)>>1;
}
void solve_small(){
char F[2500]={},G[2500]={};
for(int i=0;i<N;i++){
strncpy(F,S,i);
strncpy(F+i,S+i+1,N-1-i);
if(!strncmp(F,F+h,h)){
if(G[0]) exit(0&puts("NOT UNIQUE"));
strncpy(G,F,N-1);
}
}
if(!G[0]) exit(0&puts("NOT POSSIBLE"));
for(int i=0;i<h;i++) putchar(G[i]); puts("");
}
void solve(){
int s=0,e=N-1,xs=-1,xe=-1;
for(int i=0;i<h;i++){
if(S[i]!=S[i+h]){
s=max(s,i);
e=min(e,i+h);
if(s>e) exit(0&puts("NOT POSSIBLE"));
}
if(S[i]!=S[i+h+1]){
if(xs==-1){
xs=i+1;
xe=i+h;
} else{
xs=min(xs,i+1);
xe=max(xe,i+h);
}
}
}
}
int main(){
input();
if(N<2000) solve_small();
else solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |