Submission #468954

# Submission time Handle Problem Language Result Execution time Memory
468954 2021-08-30T09:34:12 Z paga2004 Palindromic Partitions (CEOI17_palindromic) C++14
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>

#ifdef LOCAL
#define dbg(x) cerr << "dgb: " << x << "\n";
#else
#define dbg(x)
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,tune=native")
#endif

#define int int_fast64_t

using namespace std;

string s;
int solve(int l, int r) {
  dbg("l " << l << " r " << r);
  if (l == r)
    return 1;
  int pl = l;
  int pr = r;
  while (s[pr] != s[pl]) {
    pr--;
    if (pr == pl)
      return 1;
  }
  int len = r - pr + 1;
  dbg("len " << len);
  dbg(s.substr(pl, len));
  dbg(s.substr(pr, len));
  if (s.substr(pl, len) != s.substr(pr, len)) {
    return 1;
  }
  return 2 + solve(pl + len, pr - 1);
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int t;
  cin >> t;
  while (t--) {
    cin >> s;
    dbg(s);
    int res = 0;
    int l = 0, r = (int)s.size() - 1;
    while (l < r) {
      dbg("l " << l << " r " << r);
      int len = 1;
      while (s[l] != s[r]) {
        r--;
        len++;
        if (r == l) {
          goto end;
        }
      }
      dbg("len " << len);
      dbg(s.substr(l, len));
      dbg(s.substr(r, len));
      if (s.substr(l, len) != s.substr(r, len)) {
        goto end;
      }
      res += 2;
      l += len;
      r--;
    }
  end:
    if (l <= r)
      res++;
    cout << res << "\n";
  }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -