이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define pb push_back
#define max_rng *max_element
#define min_rng *min_element
#define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define forn(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
template <class X, class Y>
inline bool maximize(X &x, Y y) {
return (x < y ? x = y, true : false);
}
template <class X, class Y>
inline bool minimize(X &x, Y y) {
return (x > y ? x = y, true : false);
}
template <class X>
inline void compress(vector<X> &a) {
sort(all(a));
a.resize(unique(all(a)) - a.begin());
}
int ctz(ll x) { return __builtin_ctzll(x); }
int lg(ll x) { return 63 - __builtin_clzll(x); }
int popcount(ll x) { return __builtin_popcount(x); }
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) {
return l + abs((ll) rng()) % (r - l + 1);
}
const ll oo = (ll) 1e17;
const int inf = (int) 1e9 + 7, mod = (int) 1e9 + 7;
const int N = 1e6 + 5, M = 2e5 + 5, BASE = 307, LOG = 23;
void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
int n;
string s;
int pw[N], pf[N];
int getRange(int i, int j) {
return (pf[j] - 1LL * pf[i - 1] * pw[j - i + 1] + 1LL * mod * mod) % mod;
}
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> s;
s = '!' + s;
if (n % 2 == 0) {
return cout << "NOT POSSIBLE", 0;
}
pw[0] = 1;
rep(i, n) pw[i] = 1LL * pw[i - 1] * BASE % mod;
pf[0] = 0;
rep(i, n) pf[i] = (1LL * pf[i - 1] * BASE + s[i] - 'A' + 1) % mod;
// cout << getRange(1, 3) << '\n';
// cout << (1LL * getRange(1, 2) * pw[1] + getRange(3, 3)) % mod << '\n';
int pos = -1;
int len = (n - 1) / 2;
forn(i, 1, n) {
bool ok = 0;
if (i == 1) {
if (getRange(2, len + 1) == getRange(len + 2, n)) {
ok = 1;
}
}
else if (i == n) {
if (getRange(1, len) == getRange(len + 1, n - 1)) {
ok = 1;
}
}
else {
if (i <= len) {
int first = getRange(1, i - 1);
first = (1LL * pw[i - 2] * first + getRange(i + 1, len + 1)) % mod;
int second = getRange(len + 2, n);
if (first == second) ok = 1;
}
else {
int first = getRange(1, len), second;
if (i == len + 1) {
second = getRange(i + 2, n);
}
else {
second = (1LL * pw[i - len - 2] * getRange(len + 1, i - 1) + 1LL * getRange(i + 1, n) ) % mod;
}
if (first == second) ok = 1;
}
}
if (ok) {
if (pos != -1) {
return cout << "NOT UNIQUE", 0;
}
pos = i;
}
}
forn(i, 1, n) {
if (i == pos) continue;
if (!len) continue;
cout << s[i];
len--;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |