Submission #1222171

#TimeUsernameProblemLanguageResultExecution timeMemory
1222171otariusPalindromic Partitions (CEOI17_palindromic)C++20
0 / 100
7 ms8256 KiB
#include <bits/stdc++.h> #include <bits/extc++.h> using namespace __gnu_pbds; using namespace std; // #pragma GCC optimize("Ofast") // #pragma GCC optimize ("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ff first #define sc second #define pb push_back #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define ull unsigned long long #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rngl(chrono::steady_clock::now().time_since_epoch().count()); #define int long long // #define int unsigned long long // #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> // #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update> const ll mod = 1e9 + 7; // const ll mod = 998244353; const ll inf = 1e9; const ll biginf = 1e18; const int maxN = 1e6 + 15; string s; int n; ll pwr[maxN], hsh[maxN]; void init() { pwr[0] = 1; for (int i = 1; i < maxN; i++) pwr[i] = (pwr[i - 1] * 31) % mod; } void init_hash() { for (int i = 1; i <= n; i++) hsh[i] = (hsh[i - 1] + (s[i] - 'a') * pwr[i] % mod) % mod; } bool check(int l1, int r1, int l2, int r2) { ll hsh1 = (hsh[r1] - hsh[l1 - 1] + mod) % mod; (hsh1 *= pwr[l2 - l1]) %= mod; ll hsh2 = (hsh[r2] - hsh[l2 - 1] + mod) % mod; return (hsh1 == hsh2); } void solve() { cin >> s; n = s.size(); s = " " + s; init_hash(); int ans = 0, i = 1, j = n, si = 1, sj = n; bool f = 0; while (i <= j) { if (check(si, i, j, sj)) { if (i == j) ans++, f = 1; else ans += 2; si = i + 1; sj = j - 1; } i++; j--; } ans += !f; cout << ans << '\n'; } int32_t main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); init(); int t = 1; cin >> t; while (t--) { solve(); // cout << '\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...