# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1147238 | gulmix | Kamenčići (COCI21_kamencici) | C++20 | 1099 ms | 171144 KiB |
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = int;
#define all(x) x.begin(), x.end()
#define oset tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
ll n, k;
char s[352];
ll dp[352][352][352];
ll pref[352];
ll solve(ll l, ll r, ll m){
if(dp[l][r][m] == -1){
ll tot = pref[n-1];
ll rtot = pref[r];
if(l)rtot -= pref[l-1];
ll ored = tot - rtot - m;
if(m >= k){
return 0;
}else if(ored >= k){
return 1;
}else{
if(!solve(l+1, r, ored) || !solve(l, r-1, ored)){
return 1;
}else{
return 0;
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
//ifstream cin("cycle2.in");
//ofstream cout("cycle2.out");
scanf("%d%d", &n, &k);
scanf("%s", s);
for(int i = 0; i < 352; i++){
for(int j = 0; j < 352; j++){
for(int k = 0; k < 352; k++){
dp[i][j][k] = -1;
}
}
}
pref[0] = (s[0] == 'C');
for(int i = 1; i < n; i++){
pref[i] = pref[i-1] + (s[i] == 'C');
}
if(solve(0, n-1, 0)){
puts("DA");
}else{
puts("NE");
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |