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 fast ios_base::sync_with_stdio();cin.tie();cout.tie();
#define en cout<<endl;
#define ops cout<<"ops"<<endl;
#define line cout<<"---------------------------"<<endl;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pllll;
typedef string str;
const ll DIM = 2e6 + 7;
const ll DIMM = 1e2 + 7;
const ll DDIM = 7;
const ll INF = 1e18 + 7;
const ll X = 1e5 + 7;
const ll BS = 2e5 + 7;
const ll AS = 26 + 7;
const ll MODULO = 1e9 + 7;
ll nt,n,m,k,q;
ll val,val1;
ll c[AS];
ll sz,p1,p2,p3,p4,fl;
vector<ll> r;
str s,s1,res;
int main()
{
fast;
//ll x1,y1,x2,y2;
cin>>n>>s;
for(int i=0; i<n; i++)
{
val=s[i]-'A'+1;
c[val]++;
}
val=(-1);
for(int i=1; i<=26; i++)
{
if(c[i]==1)val=i;
if(c[i]%2==1)k++;
}
if(n%2==0)
{
cout<<"NOT POSSIBLE"<<endl;
return 0;
}
if(k!=1)
{
cout<<"NOT POSSIBLE"<<endl;
return 0;
}
if(val!=(-1))
{
res="";
for(int i=0; i<n/2; i++)
{
val1=s[i]-'A'+1;
if(val!=val1)res+=s[i];
}
sz=res.length();
if(sz != (n/2))res+=s[n/2];
cout<<res<<endl;
return 0;
}
res="";
fl=0;
for(int j=0;j<n;j++){
if(j<=n/2){
p1=0;p2=n/2+1;
}
else{
p1=0;p2=n/2;
}
while(1){
if(p1==j)p1++;
if(p2==j)p2++;
if(s[p1]!=s[p2] || p2==(n-1))break;
p1++;
p2++;
}
if(p2!=(n-1))continue;
fl=1;
s1="";
for(int i=0;i<n/2;i++){
if(i==j)continue;
s1+=s[i];
}
sz=s1.length();
if(sz < n/2)s1+=s[n/2];
if(res=="")res=s1;
else{
cout<<"NOT UNIQUE"<<endl;
return 0;
}
}
if(fl==0){
cout<<"NOT POSSIBLE"<<endl;
return 0;
}
cout<<res<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |