Submission #556029

#TimeUsernameProblemLanguageResultExecution timeMemory
556029inventiontime세 명의 친구들 (BOI14_friends)C++17
0 / 100
9 ms7184 KiB
#include <bits/stdc++.h>
using namespace std;

#define int ll
#define endl '\n' //comment for interactive

#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define re resize
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, n) for(int i = 1; i <= n; i++)
#define print(x) cout << #x << ": " << x << endl << flush

typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
typedef array<int, 3> ti;
typedef vector<ii> vii;
typedef vector  <ti> vti;
typedef priority_queue<int> pq;

template<class T> bool ckmin(T&a, T b) { bool B = a > b; a = min(a, b); return B; }
template<class T> bool ckmax(T&a, T b) { bool B = a < b; a = max(a, b); return B; }

const int inf = 1e17;
//const int maxn = ;

string check(string a, string b) {

    // a smol b big
    int n = a.size();

    bool ok = true;
    char c = ' ';
    int i = 0, j = 0;
    while(i < n) {
        if(a[i] != b[j]) {
            if(c != ' ') { 
                ok = false;
                break;
            } else {
                c = b[j];
                j++;
            }
        } else {
            i++; j++;
        }
    }

    if(ok) return a;
    else return "";

}

void solve() {

    int n; cin >> n;
    string s; cin >> s;

    if(n <= 2 or n % 2 == 0) {
        cout << "NOT POSSIBLE" << endl;
        return;
    }

    string a1 = check(s.substr(0, n/2), s.substr(n/2, n/2 + 1));
    string a2 = check(s.substr(n/2 + 1, n/2), s.substr(0, n/2 + 1));
    if(a1 == "" and a2 == "")
        cout << "NOT POSSIBLE" << endl;
    else if(a1 == "")
        cout << a2 << endl;
    else if(a2 == "")
        cout << a1 << endl;
    else
        cout << "NOT UNIQUE" << endl;

}

signed main() {

    fast_io;

    int t = 1; //cin >> t;
    while(t--)
        solve();

    return 0;

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