제출 #1302402

#제출 시각아이디문제언어결과실행 시간메모리
1302402kawhietPalindromic Partitions (CEOI17_palindromic)C++20
60 / 100
10089 ms3276 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 47
#endif

void solve() {
    string a;
    cin >> a;
    int n = a.size();
    int ans = 0;
    string pre, suf;
    int l = 0, r = n - 1;
    while (l < r) {
        pre += a[l++];
        suf += a[r--];
        string tmp = suf;
        reverse(tmp.begin(), tmp.end());
        if (pre == tmp) {
            ans += 2;
            pre.clear();
            suf.clear();
        }
    }
    if (l <= r || !pre.empty()) {
        ans++;
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...