이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
const int mod = (int) 1e9 + 7, p = 10103;
void solve() {
int n;
string s;
cin >> n >> s;
if (n % 2 == 0) {
cout << "NOT POSSIBLE\n";
return;
}
s = s + s;
vector<int> h(s.size() + 1), pw(s.size() + 1, 1);
for (int i = 0; i < (int) s.size(); i++) {
h[i + 1] = (h[i] * 1ll * p + s[i]) % mod;
pw[i + 1] = pw[i] * 1ll * p % mod;
}
auto get = [&] (int l, int r) {
if (l > r) {
return 0;
}
int res = (h[r + 1] - h[l] * 1ll * pw[r - l + 1] % mod + mod) % mod;
return res;
};
map<int, int> ans;
for (int i = 0; i < n; i++) {
if (get(i + 1, i + n / 2) == get(i + n / 2 + 1, i + n / 2 + n / 2)) {
if (i >= n / 2) {
ans[get(0, n / 2 - 1)] = i;
} else {
ans[get(n - n / 2, n - 1)] = i;
}
}
}
if (ans.empty()) {
cout << "NOT POSSIBLE\n";
return;
}
if ((int) ans.size() > 1) {
cout << "NOT UNIQUE\n";
return;
}
s.erase(s.begin() + ans.begin()->second);
assert(s.substr(0, n / 2) == s.substr(n / 2, n / 2));
cout << s.substr(0, n / 2) << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |