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;
#define iloop(x, n) for (long long i = x; i < n; ++i)
#define jloop(x, n) for (long long j = x; j < n; ++j)
#define kloop(x, n) for (long long k = x; k < n; ++k)
#define dloop(x, n) for (long long d = x; d >= n; --d)
#define ll long long
#define pll pair<long long, long long>
#define pii pair<int, int>
#define iii tuple<int, int, int>
#define vi vector<int>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define int long long
#define endl '\n'
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
#define dg(x) cout << #x << ": " << x << endl
#define all(x) x.begin(), x.end()
#define FASTIO \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
int32_t main(){
FASTIO
int l; cin >> l;
string s;
cin >> s;
if ((l - 1) % 2 != 0) {
cout << "NOT POSSIBLE";
return 0;
}
int n = l / 2;
string lf, lb, rf, rb;
iloop(0, n){
lf += s[i];
}
iloop(n+1, l){
rf += s[i];
}
int cnt = 0;
string ans;
for (int j = n; j >= 0; j--){
if (j != n){
lf.pop_back();
lb += s[j + 1];
rf.pop_back();
rb += s[l + j - n];
}
if (lf == rf and lb == rb){
string temp = rb;
reverse(all(temp));
if (ans.length() == 0) ans = rf + temp;
cnt++;
}
}
lf = lb = rf = rb = "" ;
iloop(n, l - 1){
lf += s[i];
}
iloop(0, n){
rf += s[i];
}
for (int j = l - 1 ; j >= n; j--){
if (j != l - 1){
lf.pop_back();
lb += s[j + 1];
rf.pop_back();
rb += s[l + j - n];
}
if (lf == rf and lb == rb){
string temp = rb;
reverse(all(temp));
if (ans.length() == 0) ans = rf + temp;
cnt++;
}
}
if (cnt == 0){
cout << "NOT POSSIBLE";
}
else if (cnt == 1){
cout << ans;
}
else cout << "NOT UNIQUE";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |