제출 #629213

#제출 시각아이디문제언어결과실행 시간메모리
629213ddy888Palindromic Partitions (CEOI17_palindromic)C++17
0 / 100
7 ms8148 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("unroll-loops") using namespace std; using namespace __gnu_pbds; using ll = long long; #define pb push_back #define fi first #define si second #define ar array typedef pair<int,int> pi; typedef tuple<int,int,int> ti; template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;} template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;} template<class key, class value = null_type, class cmp = less<key> > using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); void debug_out() {cerr<<endl;} template <typename Head, typename... Tail> void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);} #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__) const int MAXN = 1000010, MOD = 1e9+9, P = 31; int n; string s; ll pref[MAXN], power[MAXN]; ll value(int i, int j) { if (i == 0) return pref[j]; return ((pref[j]-(pref[i-1]*power[j-i+1])%MOD)%MOD+MOD)%MOD; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios::badbit | ios::failbit); power[0] = 1; for (int i = 1; i < MAXN; ++i) { power[i] = power[i-1] * P; power[i] %= MOD; } int tests; cin >> tests; while (tests--) { cin >> s; n = s.size(); pref[0] = s[0]-'a'+1; for (int i = 1; i < n; ++i) { pref[i] = (pref[i-1]*P)%MOD + (s[i]-'a'+1); pref[i] %= MOD; } int lx = 0, rx = n-1, j = n-1; int ans = 0; for (int i = 0; i < n; ++i) { if (j <= i) break; if (value(lx, i) == value(j, rx)) { ans += 2; lx = i+1, rx = j-1; } --j; } cout << ans + (s[j] != s[j+1]) << '\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...