# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42977 | BThero | Three Friends (BOI14_friends) | C++14 | 96 ms | 6572 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>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
using namespace std;
char ans[2000005];
char t[2000005];
char s[2000005];
int n;
void solve() {
scanf("%d", &n);
scanf("%s", s);
if (n % 2 == 0) {
printf("NOT POSSIBLE\n");
return;
}
int len = (n - 1) / 2;
vector <int> vv;
{
int l = 0, r = len + 1;
int ps = -1;
for (int i = 1; i <= len; ++i) {
while (s[l] != s[r]) {
if (ps == -1) {
ps = l;
}
else {
ps = -2;
break;
}
++l;
}
if (ps == -2) {
break;
}
++l, ++r;
}
if (ps == -1) {
ps = len;
}
if (0 <= ps) {
vv.pb(ps);
}
}
{
int l = 0, r = len;
int ps = -1;
for (int i = 1; i <= len; ++i) {
while (s[l] != s[r]) {
if (ps == -1) {
ps = r;
}
else {
ps = -2;
break;
}
++r;
}
if (ps == -2) {
break;
}
++l, ++r;
}
if (ps == -1) {
ps = n - 1;
}
if (0 <= ps) {
vv.pb(ps);
}
}
bool ex = 0;
for (auto it : vv) {
int sz = 0;
for (int i = 0; i < n; ++i) {
if (i != it) {
t[sz++] = s[i];
}
}
bool ok = 1;
for (int i = 0; i < len; ++i) {
ok &= (t[i] == t[i + len]);
}
if (!ok) {
continue;
}
if (ex) {
for (int i = 0; i < len; ++i) {
if (t[i] != ans[i]) {
printf("NOT UNIQUE\n");
return;
}
}
}
ex = 1;
for (int i = 0; i < len; ++i) {
ans[i] = t[i];
}
}
if (!ex) {
printf("NOT POSSIBLE\n");
return;
}
for (int i = 0; i < len; ++i) {
printf("%c", ans[i]);
}
}
int main() {
#ifdef BThero
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // BThero
int tt = 1;
while (tt--) {
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |