# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1131116 | mingga | Kamenčići (COCI21_kamencici) | C++17 | 30 ms | 23108 KiB |
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 355;
int n, k, a[N];
bool dp[N][N][N];
int sf[N], pf[N];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n >> k;
for(int i = 1; i <= n; i++) {
char c; cin >> c;
a[i] = (c == 'C');
pf[i] = pf[i - 1] + a[i];
}
for(int i = n; i > 0; i--) {
sf[i] = sf[i + 1] + a[i];
}
int tot = pf[n];
for(int len = 1; len <= n; len++) {
for(int i = 1; i + len - 1 <= n; i++) {
int j = i + len - 1;
int cur = pf[i - 1] + sf[j + 1];
for(int t = 0; t <= cur; t++) {
int dak = cur - t;
if(t >= k) dp[i][j][t] = 0;
else if(dak >= k) dp[i][j][t] = 1;
else dp[i][j][t] = (!dp[i + 1][j][dak] or !dp[i][j - 1][dak]);
}
}
}
cout << (dp[1][n][0] ? "DA" : "NE");
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
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... |