Submission #856364

#TimeUsernameProblemLanguageResultExecution timeMemory
856364CyanmondPalindromic Partitions (CEOI17_palindromic)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, l, r) for (int i = (l); i < (r); ++i) #define per(i, l, r) for (int i = (r - 1); i >= l; --i) #define ALL(x) (x).begin(), (x).end() using i64 = long long; using u64 = unsigned long long; constexpr u64 mod = (1ull << 61) - 1; constexpr u64 base = 2; u64 safeMod(__uint128_t v) { while (v < 0) v += mod; return v % mod; } struct SH { static constexpr u64 mul(u64 a, u64 b) { __uint128_t x = (__uint128_t)(a) * (__uint128_t)(b); return safeMod(x % (__uint128_t)mod); } int n; string S; vector<u64> hash; SH(string s) : S(s) { n = (int)S.size(); hash.assign(n + 1, 0); rep(i, 0, n) { hash[i + 1] = safeMod(mul(hash[i], base) + (u64)(S[i])); } } }; void main_() { string S; cin >> S; const int N = (int)S.size(); string A = S.substr(0, N / 2), B = S.substr(N - N / 2, N / 2); const int M = (int)A.size(); vector<u64> baseTable(M + 10); baseTable[0] = 1; rep(i, 1, M + 10) baseTable[i] = SH::mul(baseTable[i - 1], base); SH ha(A), hb(B); auto judge = [&](int l, int r) { u64 hs1 = safeMod(ha.hash[r] - SH::mul(ha.hash[l], baseTable[r - l])); u64 hs2 = safeMod(hb.hash[M - l] - SH::mul(hb.hash[M - r], baseTable[r - l])); return hs1 == hs2; }; int l = 0, r = 0; int ans = 0; while (l != M) { while (r != M) { ++r; if (judge(l, r)) { break; } } if (not judge(l, r)) { ++ans; break; } ans += 2; l = r; if (l == M) { if (N % 2 == 1) ++ans; break; } } if (N == 1) ++ans; cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) main_(); }

Compilation message (stderr)

palindromic.cpp: In static member function 'static constexpr u64 SH::mul(u64, u64)':
palindromic.cpp:23:23: error: call to non-'constexpr' function 'u64 safeMod(__int128 unsigned)'
   23 |         return safeMod(x % (__uint128_t)mod);
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
palindromic.cpp:15:5: note: 'u64 safeMod(__int128 unsigned)' declared here
   15 | u64 safeMod(__uint128_t v) {
      |     ^~~~~~~