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;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define int long long
#define pb push_back
#define ff first
#define ss second
const int N=1e5+5;
vector<int>ans;
signed main(){
int n;
cin>>n;
string s;
set<char>st;
cin>>s;
for(int i=0;i<n;i++)st.insert(s[i]);
if(st.size()==1 and n%2){
cout<<"NOT UNIQUE";
return 0;
}
if(n%2==0){
cout<<"NOT POSSIBLE";
return 0;
}
int l1=0;
int r1=n/2+1;
int cnt1=0;
int u1=0;
int e1=0;
while(cnt1!=n/2){
if(s[l1]!=s[r1]){
l1++;
e1=1;
u1++;
if(u1==2){
e1=0;
break;
}
}
l1++;
r1++;
cnt1++;
}
int p1=1;
if(u1==2 and e1==0){
p1=0;
}
reverse(s.begin(),s.end());
int l2=0;
int r2=n/2+1;
int cnt2=0;
int u2=0;
int e2=0;
while(cnt2!=n/2){
if(s[l2]!=s[r2]){
l2++;
e2=1;
u2++;
if(u2==2){
e2=0;
break;
}
}
l2++;
r2++;
cnt2++;
}
int p2=1;
if(e1 and e2){
cout<<"NOT UNIQUE";
return 0;
}
if(u1==2 and u2==2){
cout<<"NOT POSSIBLE";
return 0;
}
reverse(s.begin(),s.end());
if(p1){
cout<<s.substr(n/2+1,n/2);
}
else{
cout<<s.substr(0,n/2);
}
}
Compilation message (stderr)
friends.cpp: In function 'int main()':
friends.cpp:73:6: warning: unused variable 'p2' [-Wunused-variable]
73 | int p2=1;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |