제출 #1011325

#제출 시각아이디문제언어결과실행 시간메모리
1011325IratePalindromic Partitions (CEOI17_palindromic)C++17
100 / 100
152 ms19804 KiB
#include<bits/stdc++.h> using namespace std; const int mxN = 1e6 + 6; const int base = 53; const int MOD = 1e9 + 7; int H[mxN], P[mxN]; int get_hash(int l, int r){ return (1LL * H[r] - 1LL * H[l - 1] * P[r - l + 1] % MOD + MOD) % MOD; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); P[0] = 1; for(int i = 1;i < mxN;++i){ P[i] = 1LL * P[i - 1] * base % MOD; } int t; cin >> t; while(t--){ string str; cin >> str; int n = (int)str.size(); str = '$' + str; for(int i = 1;i <= n;++i){ H[i] = (1LL * H[i - 1] * base % MOD + (str[i] - 'a' + 1)) % MOD; } int L = 1; int res = 0; while(L <= n / 2){ int p = L; while(p <= n / 2 && get_hash(L, p) != get_hash(n - p + 1, n - L + 1)){ p++; } if(p > n / 2)break; res += 2; L = p + 1; } if(L <= n / 2 + n % 2)res++; cout << res << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...