Submission #279927

#TimeUsernameProblemLanguageResultExecution timeMemory
279927mvanaltvorstPalindromic Partitions (CEOI17_palindromic)C++17
60 / 100
10026 ms6440 KiB
#include <iostream> #include <string> #include <vector> using namespace std; bool isPalindrome(vector<char> &lbuf, vector<char> &rbuf, int len) { int i = 0; int j = len - 1; while (j >= 0) { if (lbuf[i] != rbuf[j]) return false; j--; i++; } return true; } int main() { int t; cin >> t; for (int z = 0; z < t; z++) { string input; cin >> input; int l = 0, r = input.size() - 1; vector<char> lbuf; vector<char> rbuf; int bufSize = 0; int ans = 1; while (l < r) { lbuf.push_back(input[l]); rbuf.push_back(input[r]); bufSize++; l++; r--; if (isPalindrome(lbuf, rbuf, bufSize)) { // cout << l - bufSize << ", " << r + 1 << ": " << bufSize << endl; if (l == r+1) {ans ++;} else { ans += 2; } lbuf.clear(); rbuf.clear(); bufSize = 0; } } cout << ans << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...