Submission #35814

# Submission time Handle Problem Language Result Execution time Memory
35814 2017-12-01T01:34:20 Z funcsr Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
443 ms 9844 KB
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(xs) xs.begin(), xs.end()
using namespace std;
const int H = 12345;
const int MOD = 1000000007;

int pH[1000001];
int solve(string S) {
  int N = S.length();
  int lo = 0, hi = N-1;
  int a = 0, b = 0, n = 0, s = 0;
  while (lo < hi) {
    a = (1LL*a*H + S[lo++]) % MOD;
    b = (1LL*pH[n]*S[hi--] + b) % MOD;
    n++;
    if (a == b) a = 0, b = 0, n = 0, s += 2;
  }
  if (lo == hi) s++;
  else if (n > 0) s++;
  return s;
}

int T;
signed main() {
  pH[0] = 1;
  for (int i=1; i<=1000000; i++) pH[i] = (1LL*pH[i-1]*H)%MOD;

  cin >> T;
  rep(_, T) {
    string S;
    cin >> S;
    cout << solve(S) << "\n";
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5920 KB Output is correct
2 Correct 6 ms 5920 KB Output is correct
3 Correct 6 ms 5920 KB Output is correct
4 Correct 9 ms 5920 KB Output is correct
5 Correct 9 ms 5920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5920 KB Output is correct
2 Correct 6 ms 5920 KB Output is correct
3 Correct 6 ms 5920 KB Output is correct
4 Correct 9 ms 5920 KB Output is correct
5 Correct 9 ms 5920 KB Output is correct
6 Correct 6 ms 5920 KB Output is correct
7 Correct 3 ms 5920 KB Output is correct
8 Correct 9 ms 5920 KB Output is correct
9 Correct 6 ms 5920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5920 KB Output is correct
2 Correct 6 ms 5920 KB Output is correct
3 Correct 6 ms 5920 KB Output is correct
4 Correct 9 ms 5920 KB Output is correct
5 Correct 9 ms 5920 KB Output is correct
6 Correct 6 ms 5920 KB Output is correct
7 Correct 3 ms 5920 KB Output is correct
8 Correct 9 ms 5920 KB Output is correct
9 Correct 6 ms 5920 KB Output is correct
10 Correct 9 ms 5920 KB Output is correct
11 Correct 13 ms 5920 KB Output is correct
12 Correct 9 ms 5920 KB Output is correct
13 Correct 9 ms 5920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5920 KB Output is correct
2 Correct 6 ms 5920 KB Output is correct
3 Correct 6 ms 5920 KB Output is correct
4 Correct 9 ms 5920 KB Output is correct
5 Correct 9 ms 5920 KB Output is correct
6 Correct 6 ms 5920 KB Output is correct
7 Correct 3 ms 5920 KB Output is correct
8 Correct 9 ms 5920 KB Output is correct
9 Correct 6 ms 5920 KB Output is correct
10 Correct 9 ms 5920 KB Output is correct
11 Correct 13 ms 5920 KB Output is correct
12 Correct 9 ms 5920 KB Output is correct
13 Correct 9 ms 5920 KB Output is correct
14 Correct 386 ms 9840 KB Output is correct
15 Correct 249 ms 9844 KB Output is correct
16 Correct 443 ms 9844 KB Output is correct
17 Correct 209 ms 7920 KB Output is correct