/*
.=#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#=.
.*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%+
:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
=%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
.+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%=
.*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%:
:#%%%%%%%%%#=....-#:......-*%%*:......:**+++++++++++++#%%%#++++++++++++++%*+++++++++++++++%%%%%%#.
-%%%%%%%%+:......+%#-.....:+#-......:*%#+++++++++++++++*%%*+++++++++++++*%+++++++++++++++*%%%%%%*.
.=%%%%%%-.........#%%%-...+#-.......+%%%#+++++#####*+++++#%++++++########%%####*+++++#####%%%%%%%=.
.*%%%%%%:........-%%%%%+-#=.......=%%%%%*+++++%%%%%#+++++%#+++++#%%%%%%%%%%%%%%++++++%%%%%%%%%%%%-.
:#%%%%%%--*+.....+%%%%%%+........#%%%%%%++++++++++++++++%%*++++++++++++#%%%%%%%+++++*%%%%%%%%%%%#:
.:%%%%%%%%%%=....:#%%%%+...........*%%%%#++++++++++++++++#%+++++++++++++#%%%%%%*+++++%%%%%%%%%%%%*:
.-%%%%%%%%%#:....-%%%*..............=%%%++++++%%%%%%*++++**+++++#%%%%%%%%%%%%%%++++++%%%%%%%%%%%%+.
.+%%%%%%%%%*.....+%#:......:*-.......=%#+++++*#####*+++++#*+++++########%%%%%%#+++++#%%%%%%%%%%%%=.
.*%%%%%%%%%=....:+-.......+%%%+.......-#*+++++++++++++++##++++++++++++++*%%%%%*+++++%%%%%%%%%%%%%-
.%%%%%%%%%%:............+%%%%%%#=.......#*+++++++++++*#%%#++++++++++++++#%%%%%*++++*%%%%%%%%%%%%#-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#:
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*.
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*.
.=#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#=.
*/
#include <bits/stdc++.h>
#define fi(i, a, b) for( int i = a; i <= b; i++ )
#define fid(i, a, b) for( int i = a; i >= b; i-- )
#define getbit(x, i) ((x>>i)&1)
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define st first
#define nd second
#define mp make_pair
#define HTManh ""
#define maxn 100009
#define endl '\n'
using namespace std;
int test;
int n, k;
string s;
pii dp[359][359];
bool kq[359][359];
bool xd[359][359];
bool calc(int len, int d)
{
int c = d+len-1;
if (xd[d][c]) return kq[d][c];
xd[d][c] = 1;
if ((n-len)%2 == 0)
{
if (dp[d][c].nd == 0)
{
cout << d << " " << c << " " << 0 << endl;
return 0;
}
dp[d][c-1] = min(dp[d][c-1], {dp[d][c].st-(s[c]=='C'), dp[d][c].nd});
dp[d+1][c] = min(dp[d+1][c], {dp[d][c].st-(s[d]=='C'), dp[d][c].nd});
}
else
{
if (dp[d][c].st == 0)
{
cout << d << " " << c << " " << 1 << endl;
return 1;
}
dp[d][c-1] = min(dp[d][c-1], {dp[d][c].st, dp[d][c].nd-(s[c]=='C')});
dp[d+1][c] = min(dp[d+1][c], {dp[d][c].st, dp[d][c].nd-(s[d]=='C')});
}
bool kq1 = calc(len-1,d), kq2 = calc(len-1,d+1);
bool res = 0;
if ((n-len)%2==0)
{
if (kq1 == kq2 && kq2 == 1) res = 1;
else res = 0;
}
else
{
if (kq1 == kq2 && kq2 == 0) res = 0;
else res = 1;
}
//cout << d << " " << c << " " << res << endl;
return res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);
if (fopen(HTManh".inp", "r"))
{
freopen(HTManh".inp", "r", stdin);
freopen(HTManh".out", "w", stdout);
}
cin >> n >> k >> s;
s = ' ' + s;
fi(i,1,n) fi(j,1,n) dp[i][j] = {1e9, 1e9};
dp[1][n] = {k, k};
cout << (calc(n,1) ? "NE" : "DA");
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | freopen(HTManh".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | freopen(HTManh".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |