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;
int n;
string u, a, b, s1, s2;
int main()
{
cin >> n >> u;
if(n%2 == 0)
{
cout << "NOT POSSIBLE\n";
return 0;
}
int mid = (n-1)/2, p1 = -1, p2 = -1;
bool ok1 = true, ok2 = true;
for(int i = 0 ; i < mid ; ++i) a.push_back(u[i]);
for(int i = mid ; i < n ; ++i) b.push_back(u[i]);
for(int i = 0, j = 0; i < mid ; ++j, ++i)
{
if(a[i] != b[j])
{ if(p1 == -1 && a[i] == b[++j]) p1 = j;
else
{
ok1 = false;
break;
}
}
s1 += a[i];
}
a.clear(); b.clear();
for(int i = 0 ; i <= mid ; ++i) b.push_back(u[i]);
for(int i = mid + 1 ; i < n ; ++i) a.push_back(u[i]);
for(int i = 0, j = 0; i < mid ; ++j, ++i)
{
if(a[i] != b[j])
{ if(p2 == -1 && a[i] == b[++j]) p2 = j;
else
{
ok2 = false;
break;
}
}
s2 += a[i];
}
if(!ok1 && !ok2) cout << "NOT POSSIBLE\n";
else
{
if(ok1 && ok2 && s1 != s2) cout << "NOT UNIQUE\n";
else if(ok1) cout << s1 << "\n";
else cout << s2 << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |