# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
852937 | lovrot | Three Friends (BOI14_friends) | C++17 | 113 ms | 36556 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 <cstdio>
using namespace std;
typedef long long ll;
const int N = 2e6 + 10;
const ll B = 101;
int n;
char STR[N];
ll H[N], P[N];
int main() {
scanf("%d", &n);
P[0] = 1;
for(int i = 1; i <= n; ++i) {
P[i] = P[i - 1] * B;
scanf(" %c", STR + i);
H[i] = H[i - 1] + P[i - 1] * (ll) (STR[i] - 'A' + 1);
}
if(n == 1 || (n & 1) == 0) { printf("NOT POSSIBLE\n"); return 0; }
int m = n >> 1;
int l = -1, r = -1;
ll h = -1;
for(int i = 1; i <= n; ++i) {
if(i > m) {
ll a = H[m] * P[n - m];
ll b = H[n] - H[i] + (H[i - 1] - H[m]) * B;
if(a == b) {
if(h != -1 && b != h) { printf("NOT UNIQUE\n"); return 0; }
l = 1;
r = m;
h = b;
}
} else {
ll a = H[n] - H[m + 1];
ll b = (H[m + 1] - H[i] + H[i - 1] * B) * P[n - m - 1];
// if(i == 3) printf("%d %d\n", a, b);
if(a == b) {
if(h != -1 && b != h) { printf("NOT UNIQUE\n"); return 0; }
l = m + 2;
r = n;
h = b;
}
}
}
if(l == -1) printf("NOT POSSIBLE\n");
else {
for(int i = l; i <= r; ++i) printf("%c", STR[i]);
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |