This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#define st first
#define nd second
using lint = int64_t;
constexpr int MOD = int(1e9) + 7;
constexpr int INF = 0x3f3f3f3f;
constexpr int NINF = 0xcfcfcfcf;
constexpr lint LINF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acosl(-1.0);
// Returns -1 if a < b, 0 if a = b and 1 if a > b.
int cmp_double(double a, double b = 0, double eps = 1e-9) {
return a + eps > b ? b + eps > a ? 0 : 1 : -1;
}
using namespace std;
int n, k;
vector<int> v, pref;
int dp[355][355][355];
int getRed(int l, int r){
if(l > r) return 0;
return pref[r] - pref[l-1];
}
int solve(int l, int r, int q){
auto &DP = dp[l][r][q];
if(DP != -1)
return DP;
int q_other = getRed(1, l-1) + getRed(r+1, n) - q;
if(q >= k)
DP = 0;
else if(q_other >= k)
DP = 1;
else if( !solve(l+1, r, q_other) )
DP = 1;
else if( !solve(l, r-1, q_other) )
DP = 1;
else
DP = 0;
//cout<<l<<" "<<r<<" "<<q<<" "<<q_other<<" = "<<DP<<"\n";
return DP;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
memset(dp, -1, sizeof dp);
cin>>n>>k;
v = vector<int>(n+2);
pref = vector<int>(n+2);
string s; cin>>s;
for(int i=0; i<n; i++)
if(s[i] == 'C')
v[i+1] = 1;
for(int i=1; i<=n+1; i++)
pref[i] = pref[i-1] + v[i];
if(solve(1, n, 0))
cout<<"DA\n";
else
cout<<"NE\n";
return 0;
}
/*
[ ]Leu o problema certo???
[ ]Ver se precisa de long long
[ ]Viu o limite dos fors (é n? é m?)
[ ]Tamanho do vetor, será que é 2e5 em vez de 1e5??
[ ]Testar sample
[ ]Testar casos de borda
[ ]1LL no 1LL << i
[ ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?)
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |