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>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
string check(string s) {
int n = s.size();
int len = (n - 1) / 2;
string A = "";
for(int i=0; i<len; i++) A += s[i];
string B = "";
for(int i=len; i<n; i++) {
if(s[i] == A[B.size()]) B += s[i];
}
// cout << A << " " << B << '\n';
if(A == B) return A;
return "-1";
}
signed main() {
int n;
cin >> n;
if(n % 2 == 0) {
cout << "NOT POSSIBLE\n";
return 0;
}
string s;
cin >> s;
string A = check(s);
reverse(s.begin(), s.end());
string B = check(s);
if(A == "-1" && B == "-1") {
cout << "NOT POSSIBLE\n";
} else if(B == "-1") {
cout << A << '\n';
} else if(A == "-1") {
reverse(B.begin(), B.end());
cout << B << '\n';
} else {
reverse(B.begin(), B.end());
if(A == B) cout << A << '\n';
else cout << "NOT UNIQUE\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |