Submission #80155

# Submission time Handle Problem Language Result Execution time Memory
80155 2018-10-19T08:18:53 Z aminra Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
222 ms 41540 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e6 + 7;
const int infint = (int)1e9;
ll T, h[MAXN], pwr[MAXN], base = 37;
string s;
void hsh()
{
	h[0] = (s[0] - 'a' + 1);
	for (int i = 1; i < s.size(); i++)
		h[i] = (h[i - 1] * base % MOD + (s[i] - 'a' + 1)) % MOD;
}
ll get(int l, int r)
{
	if(l > r)
		return -1;
	ll ans = h[r];
	if(l)
		ans -= h[l - 1] * pwr[r - l + 1] % MOD, ans = (ans + MOD) % MOD;
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	pwr[0] = 1;
	for (int i = 1; i < MAXN; i++)
		pwr[i] = pwr[i - 1] * base % MOD;
	cin >> T;
	for (int i = 0; i < T; i++)
	{
		cin >> s;
		hsh();
		ll cur = 0, ans = 0, c = 1;
		for (int i = 0; i < s.size(); i++)
			if(i < s.size() - i - 1 && get(cur, i) == get(s.size() - i - 1, s.size() - cur - 1))
			{
				ans += 2, cur = i + 1;
				if(i == s.size() - i - 2)
					c = 0;
			}
		cout << ans + c << "\n";
	}
}

Compilation message

palindromic.cpp: In function 'void hsh()':
palindromic.cpp:13:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i < s.size(); i++)
                  ~~^~~~~~~~~~
palindromic.cpp: In function 'int main()':
palindromic.cpp:38:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < s.size(); i++)
                   ~~^~~~~~~~~~
palindromic.cpp:39:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(i < s.size() - i - 1 && get(cur, i) == get(s.size() - i - 1, s.size() - cur - 1))
       ~~^~~~~~~~~~~~~~~~~~
palindromic.cpp:42:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(i == s.size() - i - 2)
        ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8184 KB Output is correct
2 Correct 14 ms 8248 KB Output is correct
3 Correct 14 ms 8248 KB Output is correct
4 Correct 14 ms 8324 KB Output is correct
5 Correct 14 ms 8324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8184 KB Output is correct
2 Correct 14 ms 8248 KB Output is correct
3 Correct 14 ms 8248 KB Output is correct
4 Correct 14 ms 8324 KB Output is correct
5 Correct 14 ms 8324 KB Output is correct
6 Correct 14 ms 8324 KB Output is correct
7 Correct 13 ms 8324 KB Output is correct
8 Correct 14 ms 8324 KB Output is correct
9 Correct 14 ms 8392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8184 KB Output is correct
2 Correct 14 ms 8248 KB Output is correct
3 Correct 14 ms 8248 KB Output is correct
4 Correct 14 ms 8324 KB Output is correct
5 Correct 14 ms 8324 KB Output is correct
6 Correct 14 ms 8324 KB Output is correct
7 Correct 13 ms 8324 KB Output is correct
8 Correct 14 ms 8324 KB Output is correct
9 Correct 14 ms 8392 KB Output is correct
10 Correct 15 ms 8404 KB Output is correct
11 Correct 15 ms 8604 KB Output is correct
12 Correct 15 ms 8604 KB Output is correct
13 Correct 18 ms 8604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8184 KB Output is correct
2 Correct 14 ms 8248 KB Output is correct
3 Correct 14 ms 8248 KB Output is correct
4 Correct 14 ms 8324 KB Output is correct
5 Correct 14 ms 8324 KB Output is correct
6 Correct 14 ms 8324 KB Output is correct
7 Correct 13 ms 8324 KB Output is correct
8 Correct 14 ms 8324 KB Output is correct
9 Correct 14 ms 8392 KB Output is correct
10 Correct 15 ms 8404 KB Output is correct
11 Correct 15 ms 8604 KB Output is correct
12 Correct 15 ms 8604 KB Output is correct
13 Correct 18 ms 8604 KB Output is correct
14 Correct 222 ms 25932 KB Output is correct
15 Correct 122 ms 31420 KB Output is correct
16 Correct 206 ms 40468 KB Output is correct
17 Correct 123 ms 41540 KB Output is correct