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;
const int maxn = 2e6+10;
int n;
string num, a, b;
int get_pref(void)
{
int ind = -1;
for (int i = 0; i < n/2; i++)
{
if (a[i] != b[i]) break;
ind = i;
}
return ind;
}
int get_suf(void)
{
int ind = (n+1)/2;
for (int i = (n+1)/2-1; i >= 1; i--)
{
if (a[i] != b[i-1]) break;
ind = i;
}
return ind;
}
int main(void)
{
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> num;
if (n%2==0)
{
cout << "NOT POSSIBLE\n";
return 0;
}
int ans = 0, add = n/2, possible = -1;
bool ok = 1;
for (int i = 0; i < add; i++)
if (num[i] != num[i+add]) ok = 0;
if (ok) ans++, possible = add;
a = num.substr(0, n/2), b = num.substr(n/2, n/2+1);
int pref = get_pref(), suf = get_suf();
for (int i = 0; i < add; i++)
if (pref >= i-1 && suf <= i+1)
ans++, possible = i;
a = num.substr(0, n/2+1), b = num.substr(n/2+1, n/2);
pref = get_pref(), suf = get_suf();
for (int i = add; i < n; i++)
if (pref >= (i-add) && suf <= (i-add)+2)
ans++, possible = i;
if (!ans) cout << "NOT POSSIBLE\n";
else if (ans > 1) cout << "NOT UNIQUE\n";
else
{
for (int i = 0, ind = 0; i < n && ind < add; i++)
if (i != possible)
cout << num[i], ind++;
cout << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |