Submission #1302424

#TimeUsernameProblemLanguageResultExecution timeMemory
1302424kawhietPalindromic Partitions (CEOI17_palindromic)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h> using namespace std; constexpr int p = 31; constexpr int mod = 1e9 + 7; void solve() { string a; cin >> a; int n = a.size(); vector<int> hash(n + 1); for (int i = 0; i < n; i++) { hash[i + 1] = (hash[i] + (a[i] - 'a' + 1) * p) % mod; } int tl = 0, tr = n, l = 1, r = n; int pre = 0, suf = 0, ans = 0; while (l < r) { pre = hash[l++]; suf = hash[n] - hash[--r]; if (pre == suf) { ans += 2; } } if (l <= r || pre != suf) { ans++; } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...