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>
#define N 2000005
#define ll long long int
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("in.txt","r",stdin);freopen ("out.txt","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;
ll n,m,ar[N],sum,t,cnt[N];
char s[N];
int main()
{
fast;
cin>>n;
cin>>s+1;
// return cout<<"NOT UNIQUE",0;
if(n%2==0)
return cout<<"NOT POSSIBLE",0;
for(int i=1;i<=n;i++)
cnt[s[i]-'A'+1]++;
int flag=0;
for(int i=1;i<=26;i++)
flag+=cnt[i]%2;
if(flag!=1)
return cout<<"NOT POSSIBLE",0;
fo(i,1,26)
if(cnt[i]%2==1)
flag=i;
int tutmac=cnt[flag];
fo(i,1,26)
cnt[i]=0;
int tut=0;
fo(i,1,n/2+1)
{
cnt[s[i]-'A'+1]++;
}
// cout<<"SA"<<endl;
if(cnt[flag]>tutmac/2)
{
ll fail=0;
for(int i=1;i<=n/2+1;i++)
{
if(s[i]!=s[i+n/2+1-fail])
fail++;
}
// cout<<"HELLO"<<sp<<fail<<endl;
if(fail!=1)
return cout<<"NOT POSSIBLE",0;
if(s[1]==s[n] && s[1]==s[n/2+1] && cnt[flag]!=n/2+1)
return cout<<"NOT UNIQUE",0;
for(int i=n/2+2;i<=n;i++)
cout<<s[i];
return 0;
}
ll fail=0;
for(int i=1;i<=n/2+1;i++)
{
if(s[i-fail]!=s[i+n/2])
fail++;
}
if(fail!=1)
return cout<<"NOT POSSIBLE",0;
if(s[1]==s[n] && s[1]==s[n/2+1])
return cout<<"NOT UNIQUE",0;
for(int i=1;i<=n/2;i++)
cout<<s[i];
return 0;
}
/* cd onedrive\desktop\kod
cls
Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/
Compilation message (stderr)
friends.cpp: In function 'int main()':
friends.cpp:30:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
cin>>s+1;
~^~
friends.cpp:48:6: warning: unused variable 'tut' [-Wunused-variable]
int tut=0;
^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |