제출 #1302427

#제출 시각아이디문제언어결과실행 시간메모리
1302427kawhietPalindromic 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; string s; while (l < r) { s.push_back(a[l]); pre = hash[l++]; suf = hash[n] - hash[--r]; if (pre == suf) { s.clear(); ans += 2; } } if (l <= r || !s.empty()) { 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...