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 main()
{
int N, M;
cin >> N;
if (N % 2 == 0)
{
cout << "NOT POSSIBLE" << '\n';
return 0;
}
M = N / 2;
string S;
cin >> S;
string a = S.substr(1, M), b = S.substr(M + 1, M);
int tot = 0;
for (int i = 0; i < M; i++)
if (a[i] == b[i])
tot++;
string correct(M, '0');
int match = M;
if (tot == M)
correct = a;
for (int i = 0; i < N - 1; i++)
{
if (i < M)
{
if (a[i] == b[i])
tot--;
if (a[i] == correct[i])
match--;
a[i] = S[i];
if (a[i] == b[i])
tot++;
if (a[i] == correct[i])
match++;
}
else
{
if (a[i - M] == b[i - M])
tot--;
b[i - M] = S[i];
if (b[i - M] == a[i - M])
tot++;
}
if (tot == M)
{
if (match != M)
{
cout << "NOT UNIQUE" << '\n';
return 0;
}
if (correct[0] == '0')
correct = a;
}
}
if (correct[0] == '0')
cout << "NOT POSSIBLE" << '\n';
else
cout << correct;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |