#include <bits/stdc++.h>
#define int long long
#define double long double
#define pii pair <int,int>
#define tiii tuple <int, int, int>
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define ub(a, b) upper_bound(a.begin(), a.end(), b) - a.begin()
#define lb(a, b) lower_bound(a.begin(), a.end(), b) - a.begin()
#define ve vector
#define graph(a, n) vector <int> a[n];
#define wgraph(a, n) vector <pii> a[n];
#define emb emplace_back
#define em emplace
#define ins insert
#define er erase
#define iShowSpeed cin.tie(NULL)->sync_with_stdio(false)
using namespace std;
template <typename T>
using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const int mod = 1e9 + 7;
const int inf = 1e18;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int32_t main(){
iShowSpeed;
int n, k; cin >> n >> k;
string s; cin >> s; s = ' ' + s;
vector <vector <int>> dp(n + 1, vector <int> (n + 1, -inf));
for (int i = 0; i <= n; i++) dp[i][i] = -(s[i] == 'C');
for (int len = 1; len < n; len++) {
for (int l = 1; l + len <= n; l++) {
int r = l + len;
if (s[l] == 'P' || s[r] == 'P') {
if (s[l] == 'P') {
dp[l][r] = max(dp[l][r], -dp[l + 1][r]);
}
if (s[r] == 'P') {
dp[l][r] = max(dp[l][r], -dp[l][r - 1]);
}
}
else {
dp[l][r] = max(-dp[l + 1][r] - 1, -dp[l][r - 1] - 1);
}
}
}
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= n; j++) {
// if (dp[i][j] == -inf) cout << "X ";
// else cout << dp[i][j] << " ";
// }
// cout << "\n";
// }
cout << (dp[1][n] > 0 ? "DA" : "NE");
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |