# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
316955 | 2020-10-28T17:13:10 Z | parsabahrami | Palindromic Partitions (CEOI17_palindromic) | C++17 | 217 ms | 26744 KB |
//! Bruh Army #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define sz(x) (ll) x.size() #define all(x) (x).begin(),(x).end() #define F first #define S second ll Pow(ll a, ll b, ll md, ll ans = 1) { for (; b; b >>= 1, a = a * a % md) if (b & 1) ans = ans * a % md; return ans % md; } const ll MAXN = 1e6 + 10; const ll INF = 8e18; const ll MOD = 1e9 + 7;\ const ll base = 31; ll hsh[MAXN], pw[MAXN], n, q; char s[MAXN]; ll get(ll l, ll r) { return (hsh[r] - hsh[l - 1] * pw[r - l + 1] % MOD + MOD) % MOD; } ll memo(ll l, ll r) { if (r < l) return 0; if (l == r) return 1; ll L = l, R = r; for (; L < R; L++, R--) { if (L > R) break; if (get(l, L) == get(R, r)) return memo(L + 1, R - 1) + 2; } return 1; } void solve() { scanf("%s", s + 1); n = strlen(s + 1); hsh[0] = 0; for (ll i = 1; i <= n; i++) { hsh[i] = (hsh[i - 1] * base % MOD + s[i] - 'a' + 1) % MOD; } printf("%lld\n", memo(1, n)); } int main() { pw[0] = 1; for (ll i = 1; i < MAXN; i++) pw[i] = pw[i - 1] * base % MOD; scanf("%lld", &q); while (q--) { solve(); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 8320 KB | Output is correct |
2 | Correct | 12 ms | 8192 KB | Output is correct |
3 | Correct | 12 ms | 8192 KB | Output is correct |
4 | Correct | 12 ms | 8192 KB | Output is correct |
5 | Correct | 12 ms | 8192 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 8320 KB | Output is correct |
2 | Correct | 12 ms | 8192 KB | Output is correct |
3 | Correct | 12 ms | 8192 KB | Output is correct |
4 | Correct | 12 ms | 8192 KB | Output is correct |
5 | Correct | 12 ms | 8192 KB | Output is correct |
6 | Correct | 12 ms | 8192 KB | Output is correct |
7 | Correct | 12 ms | 8192 KB | Output is correct |
8 | Correct | 12 ms | 8192 KB | Output is correct |
9 | Correct | 12 ms | 8192 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 8320 KB | Output is correct |
2 | Correct | 12 ms | 8192 KB | Output is correct |
3 | Correct | 12 ms | 8192 KB | Output is correct |
4 | Correct | 12 ms | 8192 KB | Output is correct |
5 | Correct | 12 ms | 8192 KB | Output is correct |
6 | Correct | 12 ms | 8192 KB | Output is correct |
7 | Correct | 12 ms | 8192 KB | Output is correct |
8 | Correct | 12 ms | 8192 KB | Output is correct |
9 | Correct | 12 ms | 8192 KB | Output is correct |
10 | Correct | 14 ms | 8320 KB | Output is correct |
11 | Correct | 13 ms | 8312 KB | Output is correct |
12 | Correct | 14 ms | 8288 KB | Output is correct |
13 | Correct | 14 ms | 8320 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 8320 KB | Output is correct |
2 | Correct | 12 ms | 8192 KB | Output is correct |
3 | Correct | 12 ms | 8192 KB | Output is correct |
4 | Correct | 12 ms | 8192 KB | Output is correct |
5 | Correct | 12 ms | 8192 KB | Output is correct |
6 | Correct | 12 ms | 8192 KB | Output is correct |
7 | Correct | 12 ms | 8192 KB | Output is correct |
8 | Correct | 12 ms | 8192 KB | Output is correct |
9 | Correct | 12 ms | 8192 KB | Output is correct |
10 | Correct | 14 ms | 8320 KB | Output is correct |
11 | Correct | 13 ms | 8312 KB | Output is correct |
12 | Correct | 14 ms | 8288 KB | Output is correct |
13 | Correct | 14 ms | 8320 KB | Output is correct |
14 | Correct | 217 ms | 26744 KB | Output is correct |
15 | Correct | 125 ms | 22136 KB | Output is correct |
16 | Correct | 205 ms | 26104 KB | Output is correct |
17 | Correct | 121 ms | 17944 KB | Output is correct |