| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 318029 | parsabahrami | Palindromic Partitions (CEOI17_palindromic) | C++17 | 193 ms | 26732 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//! 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 (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
