Submission #396988

#TimeUsernameProblemLanguageResultExecution timeMemory
396988lycThree Friends (BOI14_friends)C++14
0 / 100
20 ms7124 KiB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)

const int mxN = 2e6+5;

int N, cnt;
string S, ans;

void solve(bool rev) {
    int m = N/2, l = -1, r = m+1, ok;

    ok = 1;
    FOR(i,0,m){
        ok &= S[i] == S[i+m+1];
        if (ok) l = i;
        else break;
    }

    ok = 1;
    RFOR(i,m,0){
        ok &= S[i] == S[i+m];
        if (ok) r = i;
        else break;
    }

    if (l+2 == r) {
        if (rev && l+1 == m) return;
        ans = "";
        FOR(i,0,m-1 + (l+1 < m)){
            if (i != l+1) ans += S[i];
        }
        if (rev) reverse(ALL(ans));
    }
    cnt += max(0,l+2-r+1);
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin >> N >> S;

    solve(0);
    reverse(ALL(S));
    solve(1);
    if (cnt == 0) cout << "NOT POSSIBLE" << '\n';
    else if (cnt > 1) cout << "NOT UNIQUE" << '\n';
    else cout << ans << '\n';
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...