#include <bits/stdc++.h>
using namespace std;
#define int long long // a.k.a. TLE creator
#define all(x) x.begin(), x.end()
template<class A, class B> istream& operator >>(istream &o, pair<A, B> &x){return o >> x.first >> x.second;}
template<class A, class B> ostream& operator <<(ostream &o, pair<A, B> &x){return o << x.first << ' ' << x.second << ' ';}
void setIO(){ios::sync_with_stdio(false); cin.tie(0);}
const int INF = INT_MAX, MOD = 998244353, N = 351, K = __lg(N) + 1;
int n, k;
string s;
int dp[N][N][N], pre[N]{};
bool solve(int l = 0, int r = n - 1, int val = 0){
if(~dp[l][r][val])return dp[l][r][val];
if(val >= k){
dp[l][r][val] = 0;
return false;
}
int other = pre[n - 1] - (pre[r] - (l ? pre[l - 1] : 0)) - val;
dp[l][r][val] = (!solve(l + 1, r, other) || !solve(l, r - 1, other));
return dp[l][r][val];
}
signed main(){
setIO();
memset(dp, -1, sizeof dp);
cin >> n >> k >> s;
for(int i = 0; i < n; i++){
pre[i] = (s[i] == 'C') + (i ? pre[i - 1] : 0);
}
cout << (solve() ? "DA\n" : "NE\n");
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
338848 KB |
Output is correct |
2 |
Correct |
119 ms |
338716 KB |
Output is correct |
3 |
Correct |
118 ms |
338756 KB |
Output is correct |
4 |
Correct |
119 ms |
338756 KB |
Output is correct |
5 |
Correct |
122 ms |
338756 KB |
Output is correct |
6 |
Correct |
124 ms |
338760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
338848 KB |
Output is correct |
2 |
Correct |
119 ms |
338716 KB |
Output is correct |
3 |
Correct |
118 ms |
338756 KB |
Output is correct |
4 |
Correct |
119 ms |
338756 KB |
Output is correct |
5 |
Correct |
122 ms |
338756 KB |
Output is correct |
6 |
Correct |
124 ms |
338760 KB |
Output is correct |
7 |
Correct |
118 ms |
338764 KB |
Output is correct |
8 |
Correct |
121 ms |
338804 KB |
Output is correct |
9 |
Correct |
129 ms |
338688 KB |
Output is correct |
10 |
Correct |
120 ms |
338780 KB |
Output is correct |
11 |
Correct |
121 ms |
338796 KB |
Output is correct |
12 |
Correct |
125 ms |
338744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
338848 KB |
Output is correct |
2 |
Correct |
119 ms |
338716 KB |
Output is correct |
3 |
Correct |
118 ms |
338756 KB |
Output is correct |
4 |
Correct |
119 ms |
338756 KB |
Output is correct |
5 |
Correct |
122 ms |
338756 KB |
Output is correct |
6 |
Correct |
124 ms |
338760 KB |
Output is correct |
7 |
Correct |
118 ms |
338764 KB |
Output is correct |
8 |
Correct |
121 ms |
338804 KB |
Output is correct |
9 |
Correct |
129 ms |
338688 KB |
Output is correct |
10 |
Correct |
120 ms |
338780 KB |
Output is correct |
11 |
Correct |
121 ms |
338796 KB |
Output is correct |
12 |
Correct |
125 ms |
338744 KB |
Output is correct |
13 |
Correct |
127 ms |
338828 KB |
Output is correct |
14 |
Correct |
134 ms |
338784 KB |
Output is correct |
15 |
Correct |
132 ms |
338776 KB |
Output is correct |
16 |
Correct |
130 ms |
338756 KB |
Output is correct |
17 |
Correct |
127 ms |
338756 KB |
Output is correct |
18 |
Correct |
123 ms |
338732 KB |
Output is correct |