# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
380424 | BeanZ | Three Friends (BOI14_friends) | C++14 | 34 ms | 7148 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 2e5 + 5;
long long mod = 1e9 + 7;
const int lim = 2e5;
const int lg = 19;
const int base = 311;
const long double eps = 1e-6;
ll n;
string s;
string chk(ll l1, ll r1, ll l2, ll r2){
bool flag = false;
string t;
for (int i = l1; i <= r1; i++){
if (s[i] == s[l2]){
l2++;
} else if (s[i] == s[l2 + 1] && !flag){
l2 += 2;
flag = true;
} else {
return "-1";
}
}
for (int i = l1; i <= r1; i++) t.push_back(s[i]);
return t;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("tests.inp", "r")){
freopen("tests.inp", "r", stdin);
freopen("tests.out", "w", stdout);
}
cin >> n;
cin >> s;
s = " " + s;
if ((n % 2) == 0) return cout << "NOT POSSIBLE", 0;
string one = chk(1, n / 2, n / 2 + 1, n);
string two = chk(n / 2 + 2, n, 1, n / 2 + 1);
if (one == "-1" && two == "-1") return cout << "NOT POSSIBLE", 0;
if (one != "-1" && two != "-1" && one != two) return cout << "NOT UNIQUE", 0;
if (one == "-1") return cout << two, 0;
else return cout << one, 0;
}
/*
Ans:
Out:
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |