#include <iostream>
#include <vector>
#include <string>
bool isPalindrome(const std::string& str) {
int start = 0;
int end = str.size() - 1;
while (start < end) {
if (str[start] != str[end]) {
return false;
}
start++;
end--;
}
return true;
}
int maxPalindromicPartitions(const std::string& s) {
int n = s.size();
if (n == 0) return 0;
std::vector<std::vector<int>> dp(n, std::vector<int>(n, 0));
for (int i = 0; i < n; ++i)
dp[i][i] = 1;
for (int cl=2; cl<=n; ++cl)
for (int i=0; i<n-cl+1; ++i){
int j = i+cl-1;
if (isPalindrome(s.substr(i, cl)) && cl == j-i+1)
dp[i][j] = 1;
else
dp[i][j] = std::max(dp[i][j-1], dp[i+1][j]);
}
return dp[0][n-1];
}
int main() {
int t;
std::cin >> t;
while(t--) {
std::string s;
std::cin >> s;
std::cout << maxPalindromicPartitions(s) << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |