This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
string s;
set<string> st;
void match(int l1, int r1, int l2, int r2) {
bool flag = 0; string x = "";
while(l1 <= r1) {
if(s[l1] != s[l2]) {
if(flag) return;
flag = 1; --l1;
} else x += s[l1];
++l1, ++l2;
}
if(flag || (l2 <= r2 && !flag))
st.insert(x);
}
int main(int argc, char const *argv[]) {
int n; cin >> n >> s;
if(~n & 1) return 0*puts("NOT POSSIBLE");
int x = n >> 1;
match(0, x - 1, x, n - 1);
match(x + 1, n - 1, 0, x);
if(!st.size()) puts("NOT POSSIBLE");
else if(st.size() > 1) puts("NOT UNIQUE");
else cout << *st.begin() << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |