Submission #468988

#TimeUsernameProblemLanguageResultExecution timeMemory
468988paga2004Palindromic Partitions (CEOI17_palindromic)C++14
60 / 100
10098 ms1384 KiB
#include <bits/stdc++.h> #ifdef LOCAL #define dbg(x) // cerr << "dgb: " << x << "\n"; #else #define dbg(x) #endif #define int int_fast64_t using namespace std; string s; bool compare(int l, int r, int len) { for (int i = len - 1; i >= 0; i--) { if (s[l + i] != s[r + i]) return false; } return true; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { s.clear(); cin >> s; dbg(s); int res = 0; int l = 0, r = (int)s.size() - 1; while (l <= r) { dbg("outer l " << l << " r " << r); int len = 1; while (l < r && !compare(l, r, len)) { r--; len++; dbg("inner l " << l << " r " << r); } dbg("len " << len); dbg(s.substr(l, len)); dbg(s.substr(r, len)); if (l >= r) { res++; break; } else { res += 2; l += len; r--; } dbg("l " << l << " r " << r); } cout << res << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...