This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n >> k;
string s;
cin >> s;
vector<int> pre(n + 1);
for (int i = 1; i <= n; i++) {
pre[i] = pre[i - 1] + (s[i - 1] == 'C');
}
vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(n + 1, vector<int>(pre[n] + 1)));
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= pre[n]; j++) {
dp[i][i][j] = (j + (s[i - 1] == 'C') >= k) ? 0 : 1;
}
}
for (int i = 2; i <= n; i++) {
for (int j = 1; j + i - 1 <= n; j++) {
for (int l = 0; l <= pre[n] - (pre[j + i - 1] - pre[j - 1]); l++) {
int bcnt = pre[n] - (pre[j + i - 1] - pre[j - 1]) - l;
dp[j][j + i - 1][l] = (l >= k) ? 0 : (bcnt >= k) ? 1 : (dp[j + 1][j + i - 1][bcnt] && dp[j][j + i - 2][bcnt]) ? 0 : 1;
}
}
}
cout << (dp[1][n][0] ? "DA\n" : "NE\n");
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |