Submission #1131116

#TimeUsernameProblemLanguageResultExecution timeMemory
1131116minggaKamenčići (COCI21_kamencici)C++17
70 / 70
30 ms23108 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)

Main.cpp: In function 'int main()':
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(task ".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(task ".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...