Submission #66768

# Submission time Handle Problem Language Result Execution time Memory
66768 2018-08-12T09:42:15 Z Abelyan Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
53 ms 5036 KB
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

typedef long long ll;
const int N = 100006;
const long long INF = (ll)1000000000000000007;
const ll P = 13084673;


void solve() {
	string s;
	cin >> s;
	int i = 0, j = s.length() - 1, ans = 0;
	ll hash1 = 0, hash2 = 0, pw = 1;
	while (i < j) {
		hash1 += (ll)(s[i] - 'a' + 1)*pw;
		hash2 = hash2*P + (ll)(s[j] - 'a' + 1);
		//cout << hash1 << " " << hash2 << endl;
		pw *= P;
		i++;
		j--;
		if (hash1 == hash2) {
			ans += 2;
			pw = 1;
			hash2 = 0;
			hash1 = 0;
		}
	}
	if (pw == 1 && i==j+1)
		cout << ans << endl;
	else
		cout << ans + 1 << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	int T;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 464 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 464 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 3 ms 572 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 3 ms 624 KB Output is correct
9 Correct 3 ms 628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 464 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 3 ms 572 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 3 ms 624 KB Output is correct
9 Correct 3 ms 628 KB Output is correct
10 Correct 3 ms 764 KB Output is correct
11 Correct 2 ms 820 KB Output is correct
12 Correct 3 ms 916 KB Output is correct
13 Correct 3 ms 916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 464 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 3 ms 572 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 3 ms 624 KB Output is correct
9 Correct 3 ms 628 KB Output is correct
10 Correct 3 ms 764 KB Output is correct
11 Correct 2 ms 820 KB Output is correct
12 Correct 3 ms 916 KB Output is correct
13 Correct 3 ms 916 KB Output is correct
14 Correct 53 ms 4960 KB Output is correct
15 Correct 18 ms 4960 KB Output is correct
16 Correct 30 ms 5036 KB Output is correct
17 Correct 27 ms 5036 KB Output is correct