제출 #1125460

#제출 시각아이디문제언어결과실행 시간메모리
1125460dwuyPalindromic Partitions (CEOI17_palindromic)C++17
100 / 100
46 ms18916 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int MOD = 1e9 + 9999; const int base = 307; const int MX = 2000005; int bp[MX]; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); bp[0] = 1; for(int i=1; i<MX; i++) bp[i] = bp[i-1] * base % MOD; int q; cin >> q; while(q--){ string s; cin >> s; int ans = 0; int i=0, j=(int)s.size()-1; int L = 0; int R = 0; int sz = 0; for(;i<j;i++,j--){ L = (L*base + s[i])%MOD; R = (s[j]*bp[sz] + R)%MOD; sz++; if(L == R){ ans += 2; L = R = 0; sz = 0; } } if(i <= j || L != 0 || R != 0) ans++; 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...