Submission #107563

#TimeUsernameProblemLanguageResultExecution timeMemory
107563dfistricThree Friends (BOI14_friends)C++14
0 / 100
85 ms33776 KiB
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORd(i, a, b) for (int i = (a); i >= (b); i--) #define REP(i, n) FOR(i, 0, n) #define ll long long using namespace std; const int MAXN = 2001000; ll ha[MAXN], pot[MAXN]; const int BASE = 35537, MOD = 1e9 + 7; ll val(int x, int y) { if (y < x) return 0; ll out = ha[y]; if (x) out = (out - ha[x - 1] * pot[y - x + 1]) % MOD; return out; } int main() { ios_base::sync_with_stdio(false); pot[0] = 1; FOR(i, 1, MAXN) pot[i] = (pot[i - 1] * BASE) % MOD; int n; cin >> n; string s; cin >> s; int curr = 0; REP(i, n) { curr = (curr * BASE + s[i]) % MOD; ha[i] = curr; } string out = ""; REP(i, n) { if (i <= n / 2) { ll a = (val(0, i - 1) * pot[n / 2 - i] + val(i + 1, n / 2)) % MOD; ll b = val(n / 2 + 1, n - 1); if (a != b) continue; string curr = s.substr(n / 2 + 1, n / 2); if (out != "" && out != curr) { cout << "NOT UNIQUE\n"; return 0; } else { out = curr; } } else { ll a = val(0, n / 2 - 1); ll b = (val(n / 2, i - 1) * pot[n - i - 1] + val(i + 1, n - 1)) % MOD; if (a != b) continue; string curr = s.substr(0, n / 2 - 1); if (out != "" && out != curr) { cout << "NOT UNIQUE\n"; return 0; } else { out = curr; } } } if (out == "") cout << "NOT POSSIBLE\n"; else cout << out << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...