Submission #69708

# Submission time Handle Problem Language Result Execution time Memory
69708 2018-08-21T11:54:27 Z Googal Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
162 ms 42228 KB
#include <iostream>
#include <cstring>

using namespace std;

typedef long long ll;

const ll NMAX = 1e6;
const ll MOD = 1e9;
const ll base = 26;

ll t, n;
ll mult[1 + NMAX];
ll phash[1 + NMAX];

char s[NMAX + 10];

ll solve_hash(ll le, ll ri) {
  return (phash[ri] - phash[le - 1] * mult[ri - le + 1] + MOD * MOD) % MOD;
}

void compute_mult() {
  mult[0] = 1;

  for(ll i = 1; i <= NMAX; i++)
    mult[i] = mult[i - 1] * base % MOD;
}

int main()
{
  ios_base::sync_with_stdio(false);
  compute_mult();

  cin >> t;

  for(ll test = 1; test <= t; test++) {
    cin >> (s + 1);
    n = strlen(s + 1);

    for(ll i = 1; i <= n; i++)
      phash[i] = (phash[i - 1] * base + s[i]) % MOD;

    ll le = 1;
    ll ri = n;
    ll res = 0;

    while(le <= ri) {
      ll len = 1;

      while(le + len - 1 < ri - len + 1 && solve_hash(le, le + len - 1) != solve_hash(ri - len + 1, ri))
        len++;

      if(le + len - 1 >= ri - len + 1) {
        res++;
        break;
      }

      res += 2;
      le += len;
      ri -= len;
    }

    cout << res << '\n';
  }
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8184 KB Output is correct
2 Correct 14 ms 8184 KB Output is correct
3 Correct 15 ms 8240 KB Output is correct
4 Correct 15 ms 8276 KB Output is correct
5 Correct 15 ms 8352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8184 KB Output is correct
2 Correct 14 ms 8184 KB Output is correct
3 Correct 15 ms 8240 KB Output is correct
4 Correct 15 ms 8276 KB Output is correct
5 Correct 15 ms 8352 KB Output is correct
6 Correct 14 ms 8400 KB Output is correct
7 Correct 14 ms 8400 KB Output is correct
8 Correct 18 ms 8400 KB Output is correct
9 Correct 15 ms 8400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8184 KB Output is correct
2 Correct 14 ms 8184 KB Output is correct
3 Correct 15 ms 8240 KB Output is correct
4 Correct 15 ms 8276 KB Output is correct
5 Correct 15 ms 8352 KB Output is correct
6 Correct 14 ms 8400 KB Output is correct
7 Correct 14 ms 8400 KB Output is correct
8 Correct 18 ms 8400 KB Output is correct
9 Correct 15 ms 8400 KB Output is correct
10 Correct 15 ms 8440 KB Output is correct
11 Correct 14 ms 8528 KB Output is correct
12 Correct 15 ms 8528 KB Output is correct
13 Correct 14 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8184 KB Output is correct
2 Correct 14 ms 8184 KB Output is correct
3 Correct 15 ms 8240 KB Output is correct
4 Correct 15 ms 8276 KB Output is correct
5 Correct 15 ms 8352 KB Output is correct
6 Correct 14 ms 8400 KB Output is correct
7 Correct 14 ms 8400 KB Output is correct
8 Correct 18 ms 8400 KB Output is correct
9 Correct 15 ms 8400 KB Output is correct
10 Correct 15 ms 8440 KB Output is correct
11 Correct 14 ms 8528 KB Output is correct
12 Correct 15 ms 8528 KB Output is correct
13 Correct 14 ms 8528 KB Output is correct
14 Correct 162 ms 26596 KB Output is correct
15 Correct 96 ms 32020 KB Output is correct
16 Correct 150 ms 41064 KB Output is correct
17 Correct 92 ms 42228 KB Output is correct