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;
#define int long long
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
int32_t main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;cin>>n;
if(n%2==0){
cout<<"NOT POSSIBLE";
return 0;
}
int s=n/2;
char a[n],a1[s+1],a2[s],b1[s+1],b2[s];
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<s+1;i++)a1[i]=a[i];
for(int i=0;i<s;i++)a2[i]=a[i+s+1];
for(int i=0;i<s;i++)b2[i]=a[i];
for(int i=0;i<s+1;i++)b1[i]=a[i+s];
// for(int i=0;i<s+1;i++)cout<<a1[i];
// cout<<"\n";
// for(int i=0;i<s;i++)cout<<a2[i];
// cout<<"\n";
// for(int i=0;i<s+1;i++)cout<<b1[i];
// cout<<"\n";
// for(int i=0;i<s;i++)cout<<b2[i];
// cout<<"\n";
string s1,s2;
int c=0,one=1,two=1;
for(int i=0;i<s;i++){
if(a1[i+c]==a2[i])s1+=a2[i];
else{
if(c){
one=0;
break;
}
c++;
i--;
}
}
c=0;
for(int i=0;i<s;i++){
if(b1[i+c]==b2[i])s2+=b2[i];
else{
if(c){
two=0;
break;
}
c++;
i--;
}
}
if(one==0&&two==0)cout<<"NOT POSSIBLE";
else if(one&&two){
if(s1==s2)cout<<s1;
else cout<<"NOT UNIQUE";
}else{
if(one)cout<<s1;
else cout<<s2;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |