# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105595 | luciocf | Three Friends (BOI14_friends) | C++14 | 225 ms | 8224 KiB |
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, m;
char S[maxn];
int last(string a, string b)
{
for (int i = 0; i < m; i++)
if (a[i] != b[i])
return i;
return -1;
}
bool solve1(void)
{
string a = "", b = "";
for (int i = 0; i <= m; i++)
a += S[i];
for (int i = m+1; i < n; i++)
b += S[i];
int pos = last(a, b);
if (pos == -1) return 1;
for (int i = pos+1; i <= m; i++)
if (b[i-1] != a[i])
return 0;
return 1;
}
bool solve2(void)
{
string a = "", b = "";
for (int i = 0; i < m; i++)
b += S[i];
for (int i = m; i < n; i++)
a += S[i];
int pos = last(a, b);
if (pos == -1) return 1;
for (int i = pos+1; i <= m; i++)
if (b[i-1] != a[i])
return 0;
return 1;
}
bool cmp(string a, string b)
{
for (int i = 0; i < a.size(); i++)
if (a[i] != b[i])
return 0;
return 1;
}
int main(void)
{
scanf("%d", &n);
m = n/2;
for (int i = 0; i < n; i++)
scanf(" %c", &S[i]);
if (n%2 == 0)
{
printf("NOT POSSIBLE\n");
return 0;
}
bool ok1 = solve1();
bool ok2 = solve2();
if (!ok1 && !ok2) printf("NOT POSSIBLE\n");
else if (ok1 && ok2)
{
string a = "", b = "";
for (int i = 0; i < m; i++)
a += S[i];
for (int i = m+1; i < n; i++)
b += S[i];
if (!cmp(a, b)) printf("NOT UNIQUE\n");
else cout << a << "\n";
}
else if (ok1)
{
for (int i = m+1; i < n; i++)
printf("%c", S[i]);
printf("\n");
}
else if (ok2)
{
for (int i = 0; i < m; i++)
printf("%c", S[i]);
printf("\n");
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |