제출 #1126982

#제출 시각아이디문제언어결과실행 시간메모리
1126982MinhKienPalindromic Partitions (CEOI17_palindromic)C++20
100 / 100
38 ms3956 KiB
#include <iostream> using namespace std; #define ll long long const ll MOD = 1e9 + 7; const ll base = 99999989; int t, n; string s; int main() { cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false); cin >> t; while (t--) { cin >> s; n = s.length(); s = " " + s; int ans = 1; ll one = 0, two = 0, p = 1; for (int i = 1; i * 2 <= n; ++i) { one = (one * base + s[i] - 'a' + 1) % MOD; two = ((ll)(s[n - i + 1] - 'a' + 1) * p + two) % MOD; p = p * base % MOD; if (one == two) { if (i * 2 == n) --ans; one = two = 0; p = 1; ans += 2; } } cout << ans << "\n"; } 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...