Submission #698510

# Submission time Handle Problem Language Result Execution time Memory
698510 2023-02-13T16:31:22 Z dattranxxx Palindromic Partitions (CEOI17_palindromic) C++11
100 / 100
140 ms 11664 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int M = 1e9 + 696969;
struct Hash {
  int x; 
  Hash(int x = 0): x(x) {}
  friend Hash operator + (Hash u, const Hash& v) {
    u.x += v.x;
    if (u.x >= M) u.x -= M;
    return u;
  }
  friend Hash operator - (Hash u, const Hash& v) {
    u.x -= v.x;
    if (u.x < 0) u.x += M;
    return u;
  }
  friend Hash operator * (Hash u, const Hash& v) {
    u.x = 1LL * u.x * v.x % M;
    return u;
  }
  friend bool operator == (const Hash& u, const Hash& v) {
    return u.x == v.x;
  }
};

using ull = Hash;

const int N = 1e6 + 5;

string s;

ull h[N], pw[N], base = 31;

ull get(int l, int r) {
  return h[r] - h[l - 1] * pw[r - l + 1];
}

int n;

int main() {
  cin.tie(0)->sync_with_stdio(0); cout.tie(0);
  pw[0] = 1;
  for (int i = 1; i < N; ++i) {
    pw[i] = pw[i - 1] * base;
  }
  
  int T; cin >> T;
  while (T--) {
    cin >> s; 
    n = s.size();
    s = ' ' + s;
    
    for (int i = 1; i <= n; ++i) {
      h[i] = h[i - 1] * base + s[i] - 'a' + 1;
    }
    
    int last = 1, res = 0;
    for (int i = 1; i <= n / 2; ++i) {
      if (get(last, i) == get(n - i + 1, n - last + 1)) {
        res += 2;
        last = i + 1;
      }
    }
    if (last <= (n + 1) / 2) {
      res += 1;
    }
    cout << res << '\n';
    
  }
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 8 ms 8020 KB Output is correct
2 Correct 9 ms 8020 KB Output is correct
3 Correct 8 ms 8020 KB Output is correct
4 Correct 8 ms 8148 KB Output is correct
5 Correct 8 ms 8144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8020 KB Output is correct
2 Correct 9 ms 8020 KB Output is correct
3 Correct 8 ms 8020 KB Output is correct
4 Correct 8 ms 8148 KB Output is correct
5 Correct 8 ms 8144 KB Output is correct
6 Correct 9 ms 8144 KB Output is correct
7 Correct 8 ms 8140 KB Output is correct
8 Correct 8 ms 8148 KB Output is correct
9 Correct 9 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8020 KB Output is correct
2 Correct 9 ms 8020 KB Output is correct
3 Correct 8 ms 8020 KB Output is correct
4 Correct 8 ms 8148 KB Output is correct
5 Correct 8 ms 8144 KB Output is correct
6 Correct 9 ms 8144 KB Output is correct
7 Correct 8 ms 8140 KB Output is correct
8 Correct 8 ms 8148 KB Output is correct
9 Correct 9 ms 8148 KB Output is correct
10 Correct 9 ms 8148 KB Output is correct
11 Correct 9 ms 8144 KB Output is correct
12 Correct 9 ms 8192 KB Output is correct
13 Correct 10 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8020 KB Output is correct
2 Correct 9 ms 8020 KB Output is correct
3 Correct 8 ms 8020 KB Output is correct
4 Correct 8 ms 8148 KB Output is correct
5 Correct 8 ms 8144 KB Output is correct
6 Correct 9 ms 8144 KB Output is correct
7 Correct 8 ms 8140 KB Output is correct
8 Correct 8 ms 8148 KB Output is correct
9 Correct 9 ms 8148 KB Output is correct
10 Correct 9 ms 8148 KB Output is correct
11 Correct 9 ms 8144 KB Output is correct
12 Correct 9 ms 8192 KB Output is correct
13 Correct 10 ms 8148 KB Output is correct
14 Correct 140 ms 10224 KB Output is correct
15 Correct 76 ms 10088 KB Output is correct
16 Correct 127 ms 11664 KB Output is correct
17 Correct 73 ms 9196 KB Output is correct