Submission #1130083

#TimeUsernameProblemLanguageResultExecution timeMemory
1130083nabeul001Palindromic Partitions (CEOI17_palindromic)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h> using namespace std; // Helper function to check if a substring is a palindrome bool is_palindrome(const string &s, int l, int r) { while (l < r) { if (s[l] != s[r]) return false; l++; r--; } return true; } int max_palindromic_partition(const string &s) { int n = s.size(); int chunks = 0; int i = 0; while (i < n) { for (int j = n - 1; j >= i; --j) { if (is_palindrome(s, i, j)) { chunks++; i = j + 1; // Move past the current palindrome break; } } } return chunks; } int main() { int t; cin >> t; while (t--) { string s; cin >> s; cout << max_palindromic_partition(s) << "\n"; } 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...