제출 #574363

#제출 시각아이디문제언어결과실행 시간메모리
574363tamthegod세 명의 친구들 (BOI14_friends)C++14
100 / 100
101 ms63924 KiB
#include<iostream> #include<iomanip> #include<algorithm> #include<stack> #include<queue> #include<string> #include<string.h> #include<cmath> #include<vector> #include<map> #include<unordered_map> #include<set> #include<unordered_set> #include<cstdio> #include<bitset> #include<chrono> #include<random> #include<ext/rope> /* ordered_set #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> */ #define pb push_back #define fi first #define se second using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; const int maxN = 3e6 + 5; const int mod = 1e9 + 7; const ll oo = 1e18; #define int long long string s; const int base = 31; int n; ll Hash[maxN], poww[maxN]; inline void FastInput() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } void Prepair() { poww[0] = 1; for(int i=1; i<maxN; i++) poww[i] = (poww[i - 1] * base) % mod; } void ReadInput() { cin >> n >> s; s = ' ' + s; for(int i=1; i<=n; i++) Hash[i] = (Hash[i - 1] * base + s[i] - 'a' + 1) % mod; } int gethash(int l, int r) { return (Hash[r] - Hash[l - 1] * poww[r - l + 1] + 1LL * mod * mod) % mod; } ll Power(ll a, ll b) { if(b == 0) return 1; ll t = (Power(a, b / 2)); if(b & 1) return t * t % mod * a % mod; return t * t % mod; } void Solve() { if(!(n & 1)) { cout << "NOT POSSIBLE"; return; } vector<int> res; for(int i=1; i<=n; i++) { ll _hash1, _hash2; if(i <= n / 2) { ll t1 = gethash(1, i - 1); ll t2 = gethash(i + 1, n / 2 + 1); t1 *= poww[n / 2 - i + 1]; t1 %= mod; _hash1 = (t1 + t2) % mod; _hash2 = gethash(n / 2 + 2, n); } else { _hash1 = gethash(1, n / 2); ll t1 = gethash(n / 2 + 1, i - 1); ll t2 = gethash(i + 1, n); t1 *= poww[n - i]; t1 %= mod; _hash2 = (t1 + t2) % mod; } if(_hash1 == _hash2) res.pb(i); } if(res.size() > 1) { string s1, s2; s1 = s; s2 = s; s1.erase(s1.begin() + 1); s2.pop_back(); if(res[0] == 1 && res.back() == n && s1 != s2) { cout << "NOT UNIQUE"; return; } } if(res.empty()) { cout << "NOT POSSIBLE"; return; } s.erase(s.begin() + res[0]); for(int i=1; i<=n/2; i++) cout << s[i]; } int32_t main() { //freopen("x.inp", "r", stdin); FastInput(); Prepair(); ReadInput(); Solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...