This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Call my Name and Save me from The Dark
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
const int N = 2e6 + 10, MOD[] = {696969569, (int) 1e9 + 9};
int n, H[2][N], pw[2][N], base = 70; char S[N]; vector<int> R;
pii get(int l, int r) {
if (r < l) return {0, 0};
pii h;
h.F = (H[0][r] - 1ll * H[0][l - 1] * pw[0][r - l + 1] % MOD[0] + MOD[0]) % MOD[0];
h.S = (H[1][r] - 1ll * H[1][l - 1] * pw[1][r - l + 1] % MOD[1] + MOD[1]) % MOD[1];
return h;
}
int main() {
pw[0][0] = pw[1][0] = 1;
for (int i = 1; i < N; i++) for (int j = 0; j < 2; j++) pw[j][i] = 1ll * base * pw[j][i - 1] % MOD[j];
scanf("%d%s", &n, S + 1);
if (n % 2 == 0) return !printf("NOT POSSIBLE\n");
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 2; j++) H[j][i] = (1ll * H[j][i - 1] * base % MOD[j] + S[i] - 'A' + 1) % MOD[j];
}
for (int i = 1; i <= n; i++) {
if (i > n / 2) {
pii h = get(1, n / 2), l = get(n / 2 + 1, i - 1), r = get(i + 1, n);
l = {(1ll * l.F * pw[0][n - i] % MOD[0] + r.F) % MOD[0], (1ll * l.S * pw[1][n - i] % MOD[1] + r.S) % MOD[1]};
if (h == l) R.push_back(i);
} else {
pii h = get(n / 2 + 2, n), l = get(1, i - 1), r = get(i + 1, n / 2 + 1);
l = {(1ll * l.F * pw[0][n / 2 - i + 1] % MOD[0] + r.F) % MOD[0], (1ll * l.S * pw[1][n / 2 - i + 1] % MOD[1] + r.S) % MOD[1]};
if (h == l) R.push_back(i);
}
}
if (!SZ(R)) printf("NOT POSSIBLE\n");
else if (SZ(R) > 1) printf("NOT UNIQUE\n");
else {
int id = R[0];
for (int i = 1, j = 0; i <= n && j < n / 2; i++) {
if (i == id) continue;
else {
printf("%c", S[i]), j++;
}
}
}
return 0;
}
Compilation message (stderr)
friends.cpp: In function 'int main()':
friends.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
27 | scanf("%d%s", &n, S + 1);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |