| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1285401 | lmquan | Three Friends (BOI14_friends) | C++20 | 1 ms | 568 KiB |
#define taskname ""
#include <bits/stdc++.h>
using namespace std;
const int kBase = 647;
const int kMod = 454539497;
int main() {
if (fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
string u;
cin >> u;
n = (int)u.size();
if (n % 2 == 0) {
cout << "NOT POSSIBLE";
} else {
vector<int> p(n), q(n);
for (int i = 0; i < n; i++) {
p[i] = ((i > 0 ? 1LL * p[i - 1] * kBase : 0) + (u[i] - 'A' + 1)) % kMod;
q[i] = (i > 0 ? 1LL * q[i - 1] * kBase : 1) % kMod;
}
auto G = [&](int l, int r) -> int {
return ((p[r] - 1LL * p[l - 1] * q[r - l + 1]) % kMod + kMod) % kMod;
};
string k = "";
int v;
for (int i = 0; i < n; i++) {
int j = (i > 0 ? p[min(n / 2 - 1, i - 1)] : 0);
int x = (1LL * j * q[max(0, n / 2 - i)] + (i < n / 2 ? G(i + 1, n / 2) : 0)) % kMod;
int y = (i <= n / 2 ? G(n / 2 + 1, n - 1) : 1LL * G(n / 2, i - 1) * q[n - i - 1] + G(i + 1, n - 1)) % kMod;
if (x == y) {
if (!k.empty() && x != v) {
cout << "NOT UNIQUE";
return 0;
}
if (k.empty()) {
if (i <= n / 2) {
k = u.substr(n / 2 + 1, n / 2);
} else {
k = u.substr(0, n / 2);
}
}
v = x;
}
}
cout << (k.empty() ? "NOT POSSIBLE" : k);
}
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
