Submission #1357891

#TimeUsernameProblemLanguageResultExecution timeMemory
1357891tull세 명의 친구들 (BOI14_friends)C++20
0 / 100
1095 ms8092 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(),cnt=0;
    cin>>n;
    cin>>a;
    if(n%2==0){
        cout<<"NOT POSSIBLE";
    }
    for(auto&e:a)c+=e;
    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 j=0;j<(n-1)/2;++j){
           // cout<<h[j]<<' '<<h[j+(n-1)/2]<<'\n';
            if(h[j]!=h[j+(n-1)/2]){
                fl=0;
                break;
            }
        }
        if(fl){
            ans=h;
            ++cnt;
            st.emplace(h);
        }
    }
    if(cnt==0){
        cout<<"NOT POSSIBLE";
    }else if(cnt>1){
        cout<<"NOT UNIQUE";
    }else{
        //cout<<ans;
        for(int i=0;i<(n-1)/2;++i){
            cout<<ans[i];
        }
    }
}
/*
3
print
the
poem

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