Submission #1285401

#TimeUsernameProblemLanguageResultExecution timeMemory
1285401lmquanThree Friends (BOI14_friends)C++20
0 / 100
1 ms568 KiB
#define taskname "" #include <bits/stdc++.h> using namespace std; const int kBase = 647; const int kMod = 454539497; int main() { if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; string u; cin >> u; n = (int)u.size(); if (n % 2 == 0) { cout << "NOT POSSIBLE"; } else { vector<int> p(n), q(n); for (int i = 0; i < n; i++) { p[i] = ((i > 0 ? 1LL * p[i - 1] * kBase : 0) + (u[i] - 'A' + 1)) % kMod; q[i] = (i > 0 ? 1LL * q[i - 1] * kBase : 1) % kMod; } auto G = [&](int l, int r) -> int { return ((p[r] - 1LL * p[l - 1] * q[r - l + 1]) % kMod + kMod) % kMod; }; string k = ""; int v; for (int i = 0; i < n; i++) { int j = (i > 0 ? p[min(n / 2 - 1, i - 1)] : 0); int x = (1LL * j * q[max(0, n / 2 - i)] + (i < n / 2 ? G(i + 1, n / 2) : 0)) % kMod; int y = (i <= n / 2 ? G(n / 2 + 1, n - 1) : 1LL * G(n / 2, i - 1) * q[n - i - 1] + G(i + 1, n - 1)) % kMod; if (x == y) { if (!k.empty() && x != v) { cout << "NOT UNIQUE"; return 0; } if (k.empty()) { if (i <= n / 2) { k = u.substr(n / 2 + 1, n / 2); } else { k = u.substr(0, n / 2); } } v = x; } } cout << (k.empty() ? "NOT POSSIBLE" : k); } return 0; }

Compilation message (stderr)

friends.cpp: In function 'int main()':
friends.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen(taskname".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
friends.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen(taskname".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...