Submission #622671

# Submission time Handle Problem Language Result Execution time Memory
622671 2022-08-04T13:15:37 Z enter_hedgehog_poly Palindromic Partitions (CEOI17_palindromic) C++11
100 / 100
57 ms 11008 KB
//Palindromiczny podział
#include <bits/stdc++.h>

using namespace std;

char buff[1000010];

typedef uint64_t ll;
const ll P = 31;
const ll MOD_N = 31;
const ll MOD = ((ll) 1 << MOD_N) - 1;

inline ll FMOD(ll x) { return ((x) >> MOD_N) + ((x) & MOD); }

int main() {
	int t;
	scanf("%d", &t);
	while(t--) {
		scanf("%s", buff + 1);
		int n = strlen(buff + 1);

		ll left = 0, right = 0, exp = 1;
		int lp = 1, res = 0;

		for(int i = 1; i <= n / 2; i++) {
			left = FMOD(left + (buff[i] - 'a' + 1) * exp);
			exp = FMOD(exp * P);
			right = FMOD(right * P + (buff[n + 1 - i] - 'a' + 1));
			if(left == right) {
				exp = 1;
				left = right = 0;
				res += 2;
				lp = i + 1;
			}
		}

		if(lp != (n / 2) + 1 || (n & 1)) res++;

		printf("%d\n", res);
	}
	return 0;
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  scanf("%d", &t);
      |  ~~~~~^~~~~~~~~~
palindromic.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   scanf("%s", buff + 1);
      |   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 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 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 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 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 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 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 372 KB Output is correct
12 Correct 1 ms 412 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 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 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 372 KB Output is correct
12 Correct 1 ms 412 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 53 ms 11008 KB Output is correct
15 Correct 31 ms 6372 KB Output is correct
16 Correct 57 ms 10476 KB Output is correct
17 Correct 27 ms 5884 KB Output is correct