#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define sz(x) ((int)(x).size())
int ar[355];
int dp[355][355][355];
int pre[355];
int suf[355];
int n,k;
int f(int l,int r,int c){
int u = (l-1+n-r)&1;
int c2 = pre[l-1] + suf[r+1] - c;
if(c==k) return 0;
if(c2==k) return 1;
if(dp[l][r][c]!=-1) return dp[l][r][c];
int b=0,s=0;
if(f(l+1,r,c+(u==0 && ar[l]))) b=1;
else s=1;
if(f(l,r-1,c+(u==0 && ar[r]))) b=1;
else s=1;
if(!u){
if(b) return dp[l][r][c]=1;
return dp[l][r][c]=0;
}
if(s) return dp[l][r][c]=0;
return dp[l][r][c]=1;
}
void solve(){
memset(dp,-1,sizeof(dp));
cin >> n >> k;
string s;
cin >> s;
for(int i=1;i<=n;i++) ar[i]=(s[i-1]=='C');
pre[0]=0;
for(int i=1;i<=n;i++) pre[i]=pre[i-1]+ar[i];
suf[n+1]=0;
for(int i=n;i>=1;i--) suf[i]=suf[i+1]+ar[i];
int xd = f(1,n,0);
if(xd) cout << "DA\n";
else cout << "NE\n";
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;//cin >> t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
350544 KB |
Output is correct |
2 |
Correct |
38 ms |
350548 KB |
Output is correct |
3 |
Correct |
38 ms |
350548 KB |
Output is correct |
4 |
Correct |
38 ms |
350608 KB |
Output is correct |
5 |
Correct |
38 ms |
350484 KB |
Output is correct |
6 |
Correct |
37 ms |
350540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
350544 KB |
Output is correct |
2 |
Correct |
38 ms |
350548 KB |
Output is correct |
3 |
Correct |
38 ms |
350548 KB |
Output is correct |
4 |
Correct |
38 ms |
350608 KB |
Output is correct |
5 |
Correct |
38 ms |
350484 KB |
Output is correct |
6 |
Correct |
37 ms |
350540 KB |
Output is correct |
7 |
Correct |
40 ms |
350504 KB |
Output is correct |
8 |
Correct |
38 ms |
350548 KB |
Output is correct |
9 |
Correct |
38 ms |
350548 KB |
Output is correct |
10 |
Correct |
37 ms |
350548 KB |
Output is correct |
11 |
Correct |
37 ms |
350548 KB |
Output is correct |
12 |
Correct |
38 ms |
350544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
350544 KB |
Output is correct |
2 |
Correct |
38 ms |
350548 KB |
Output is correct |
3 |
Correct |
38 ms |
350548 KB |
Output is correct |
4 |
Correct |
38 ms |
350608 KB |
Output is correct |
5 |
Correct |
38 ms |
350484 KB |
Output is correct |
6 |
Correct |
37 ms |
350540 KB |
Output is correct |
7 |
Correct |
40 ms |
350504 KB |
Output is correct |
8 |
Correct |
38 ms |
350548 KB |
Output is correct |
9 |
Correct |
38 ms |
350548 KB |
Output is correct |
10 |
Correct |
37 ms |
350548 KB |
Output is correct |
11 |
Correct |
37 ms |
350548 KB |
Output is correct |
12 |
Correct |
38 ms |
350544 KB |
Output is correct |
13 |
Correct |
37 ms |
350800 KB |
Output is correct |
14 |
Correct |
59 ms |
350620 KB |
Output is correct |
15 |
Correct |
41 ms |
350544 KB |
Output is correct |
16 |
Correct |
57 ms |
350664 KB |
Output is correct |
17 |
Correct |
50 ms |
350548 KB |
Output is correct |
18 |
Correct |
46 ms |
350544 KB |
Output is correct |