# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
625403 | 2022-08-10T11:15:37 Z | Alma | Palindromic Partitions (CEOI17_palindromic) | C++17 | 189 ms | 27904 KB |
#include <bits/stdc++.h> using namespace std; #define fi first #define se second using ll = long long; using ii = pair<int,int>; const int INF = 1e9; const ll LLINF = 1e18; using vi = vector<int>; using vvi = vector<vi>; void setIO (string fileName) { ios::sync_with_stdio(false); cin.tie(NULL); if (fileName != "std") { freopen((fileName + ".in").c_str(), "r", stdin); freopen((fileName + ".out").c_str(), "w", stdout); } } int main() { setIO("std"); int tc; cin >> tc; while (tc--) { string s; cin >> s; int n = s.size(); ll B = 239, M = 1e9+7; vector<ll> p(n+1), hs(n+1); p[0] = 1; hs[0] = 0; for (int i = 0; i < n; i++) { p[i+1] = (p[i] * B) % M; hs[i+1] = (hs[i] * B + s[i]) % M; } int l = 0, r = n, ans = 0; while (l < r) { int k = 0; ll hs1 = 0, hs2 = 1; while (hs1 != hs2) { k++; hs1 = hs[l+k] - (hs[l] * p[k]) % M; hs2 = hs[r] - (hs[r-k] * p[k]) % M; if (hs1 < 0) hs1 += M; if (hs2 < 0) hs2 += M; } if (r-l == k) ans++; else ans += 2; l += k; r -= k; } cout << ans << '\n'; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 2 ms | 596 KB | Output is correct |
11 | Correct | 1 ms | 540 KB | Output is correct |
12 | Correct | 2 ms | 560 KB | Output is correct |
13 | Correct | 2 ms | 548 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 2 ms | 596 KB | Output is correct |
11 | Correct | 1 ms | 540 KB | Output is correct |
12 | Correct | 2 ms | 560 KB | Output is correct |
13 | Correct | 2 ms | 548 KB | Output is correct |
14 | Correct | 189 ms | 27904 KB | Output is correct |
15 | Correct | 104 ms | 22656 KB | Output is correct |
16 | Correct | 174 ms | 26216 KB | Output is correct |
17 | Correct | 92 ms | 15100 KB | Output is correct |