Submission #1357869

#TimeUsernameProblemLanguageResultExecution timeMemory
1357869tullThree Friends (BOI14_friends)C++20
0 / 100
1095 ms8156 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(A) A.begin(),A.end()
#define bp '\n'
#define vp cout<<'\n';
const int N=2e5+5;
int d[200];
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    string a,b,c;
    int n=a.size();
    cin>>n;
    cin>>a;
    for(auto&e:a){
        ++d[e];
        c+=e;
    }
    int cnt=0;
    for(int i=0;i<200;++i){
        if(d[i]%2==1){
            ++cnt;
        }
    }
    if(cnt>1 or a.size()%2==0){
        cout<<"NOT POSSIBLE";
    }else{

        cnt=0;
        string ans;
        unordered_set<string>st;
        for(int i=0;i<n;++i){
            reverse(all(c));
            c.pop_back();
            reverse(all(c));
            if(i>0)b+=a[i-1];
            string h=b;
            h+=c;
           //cout<<b<<":"<<c<<' '<<h<<'\n';
            int fl=1;
            for(int i=0;i<(n-1)/2;++i){
               // cout<<h[i]<<' '<<h[i+(n-1)/2]<<'\n';
                if(h[i]!=h[i+(n-1)/2]){
                    fl=0;
                    break;
                }
            }
            if(fl){
                ans=h;
                //++cnt;
                st.emplace(h);
            }
        }
        if(st.size()>1){
            cout<<"NOT UNIQUE";
        }else{
            cout<<ans;
        }
    }
    cout<<'\n';
}
/*
3
print
the
poem

*/
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...