Submission #917052

#TimeUsernameProblemLanguageResultExecution timeMemory
917052sleepntsheepThree Friends (BOI14_friends)C++17
0 / 100
50 ms52296 KiB
#include <iostream> #include <fstream> #include <iomanip> #include <cmath> #include <cassert> #include <cstring> #include <math.h> #include <vector> #include <algorithm> #include <deque> #include <set> #include <utility> #include <array> #include <complex> using u32 = unsigned; using i32 = int; using i64 = long long; using u64 = unsigned long long; using f64 = double; using f80 = long double; using namespace std; using pt = complex<f80>; #define ALL(x) begin(x), end(x) #define ShinLena cin.tie(nullptr)->sync_with_stdio(false); #define N 3000005 string u; int n; constexpr i64 B = 137, M = 998224353; i64 a[N], bp[N], ibp[N]; i64 bpowc(i64 a, i64 b) { if (!b) return 1; i64 r = bpowc(a, b>>1); if (b&1) return r*r%M*a%M; return r*r%M; } int main() { ShinLena; cin >> n >> u; u = " " + u; bp[0] = 1; for (int i = 1; i <= n + 1; ++i) bp[i] = bp[i-1] * B % M; i64 IB = bpowc(B, M-2); for (int i = n; i >= 1; --i) ibp[i] = bp[i+1] * IB % M; for (int i = 1; i <= n; ++i) a[i] = (a[i-1] + u[i] * bp[i-1] % M) % M; set<i64> S; int at = 0; for (int i = 1; i <= n; ++i) { if (i > n / 2) { i64 fst = a[n/2]; i64 lst = (a[i-1] - a[n/2] + M) % M; lst = (lst + (a[n] - a[i] + M) % M * IB % M) % M; fst = fst * bp[n/2] % M; if (fst == lst) at = i, S.insert(lst * ibp[n/2] % M); } else { i64 fst = (a[i-1] + (a[n/2+1] - a[i] + M) % M * IB % M) % M; i64 lst = (a[n] - a[n/2+1] + M) % M; fst = fst * bp[n/2+1] % M; if (fst == lst) at = i, S.insert(lst * ibp[n/2+1] % M); } } if (S.empty()) { cout << "NOT POSSIBLE"; } else if (S.size() > 1) { cout << "NOT UNIQUE"; } else { u.erase(u.begin() + at); cout << u.substr(1, n/2); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...