제출 #135626

#제출 시각아이디문제언어결과실행 시간메모리
135626forelax세 명의 친구들 (BOI14_friends)C++14
0 / 100
120 ms4464 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int m;cin>>m; if(m%2==0||m==1){ cout<<"NOT POSSIBLE"; return 0; } string a; cin>>a; int n=m/2; int cmn=0; for(int i = n ; i >= 0 ; i -- ) if(a[i]==a[n+i])cmn++; else break; int rez=0; int ps; if(cmn>=n){ rez++; ps=0; } for(int i = 0 ; i <= n ; i ++){ if(a[i]!=a[n+1+i])break; if(i+1+cmn>=n){ rez++; if(rez==1) ps=i+1; else{ cout<<"NOT UNIQUE"; return 0; } } } cmn=0; for(int i = n-1 ; i >= 0 ; i -- ) if(a[i]==a[n+1+i])cmn++; else break; if(cmn>=n){ rez++; if(rez==1){ ps=n; }else{ cout<<"NOT UNIQUE"; return 0; } } for(int i = 0 ; i <= n ; i ++){ if(a[i]!=a[n+i])break; if(i+1+cmn>=n){ rez++; if(rez==1) ps=i+1; else{ cout<<"NOT UNIQUE"; return 0; } } } if(rez){ if(ps<=n){ cout<<a.substr(n+1); }else{ cout<<a.substr(0,n); } }else{ cout<<"NOT POSSIBLE"; return 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...