제출 #1097335

#제출 시각아이디문제언어결과실행 시간메모리
1097335anhthi세 명의 친구들 (BOI14_friends)C++14
0 / 100
17 ms12800 KiB
#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 + 1LL * getRange(i + 1, len + 1)) % mod; if (first == getRange(len + 2, n)) ok = 1; } else { int 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 (getRange(1, len) == second) ok = 1; } } if (ok) { if (pos != -1) { return cout << "NOT UNIQUE", 0; } pos = i; } } if (pos == -1) { return cout << "NOT POSSIBLE", 0; } forn(i, 1, n) { if (i == pos) continue; if (!len) continue; cout << s[i]; len--; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...