#include <bits/stdc++.h>
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long int ll;
using namespace std;
int main() {
owo
int n, k; cin >> n >> k; bool ok = 0;
deque<char> c(n); bool t = 1; vector<int> cnt(2);
for (int i = 0; i < n; i++) cin >> c[i];
while (c.size() > 1) {
t = !t;
if (cnt[0] == k) {cout << "NE"; ok = 1; break;}
if (cnt[1] == k) {cout << "DA"; ok = 1; break;}
if (c.front() == 'P') {c.pop_front(); continue;}
if (c.back() == 'P') {c.pop_back(); continue;}
cnt[t]++;
if (c[1] == 'C') {c.pop_front(); continue;}
if (c[c.size()-2] == 'C') {c.pop_back(); continue;}
int L = 0, R = 0;
for (int i = 1; i < c.size(); i++) {
if (c[i] == 'P') L++;
else break;
}
for (int i = c.size()-2; i >= 0; i--) {
if (c[i] == 'P') R++;
else break;
}
if (L < R) c.pop_front();
else c.pop_back();
}
if (!ok) cout << "NE";
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... |