Submission #1056999

# Submission time Handle Problem Language Result Execution time Memory
1056999 2024-08-13T13:01:15 Z Thanhs Kamenčići (COCI21_kamencici) C++14
70 / 70
32 ms 175556 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define double long double
 
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
#define fi first
#define se second
#define all(x) x.begin(), x.end()
 
// mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
// int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}

const int NM = 350 + 5;
const int inf = 1e9;

string s;
int pf[NM], sf[NM], n, k;
signed dp[NM][NM][NM];

bool DP(int l, int r, int c)
{
    if (~dp[l][r][c])
        return dp[l][r][c];
    dp[l][r][c] = 0;
    int o = pf[l - 1] + sf[r + 1] - c;
    if (c + (s[l] == 'C') < k)
        dp[l][r][c] |= !DP(l + 1, r, o);
    if (c + (s[r] == 'C') < k)
        dp[l][r][c] |= !DP(l, r - 1, o);
    return dp[l][r][c];
}

void solve()
{
    memset(dp, -1, sizeof dp);
    cin >> n >> k >> s;
    s = ' ' + s;
    for (int i = 1; i <= n; i++)
        pf[i] = pf[i - 1] + (s[i] == 'C');
    for (int i = n; i >= 1; i--)
        sf[i] = sf[i + 1] + (s[i] == 'C');
    cout << (DP(1, n, 0) ? "DA" : "NE");
}

signed main()
{
    fastIO
    if (fopen("in.txt", "r")) 
    {
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
    int tc = 1;
    // cin >> tc;
    while (tc--)
        solve();
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 175452 KB Output is correct
2 Correct 18 ms 175524 KB Output is correct
3 Correct 18 ms 175452 KB Output is correct
4 Correct 18 ms 175332 KB Output is correct
5 Correct 19 ms 175452 KB Output is correct
6 Correct 18 ms 175448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 175452 KB Output is correct
2 Correct 18 ms 175524 KB Output is correct
3 Correct 18 ms 175452 KB Output is correct
4 Correct 18 ms 175332 KB Output is correct
5 Correct 19 ms 175452 KB Output is correct
6 Correct 18 ms 175448 KB Output is correct
7 Correct 18 ms 175452 KB Output is correct
8 Correct 18 ms 175452 KB Output is correct
9 Correct 18 ms 175500 KB Output is correct
10 Correct 19 ms 175444 KB Output is correct
11 Correct 19 ms 175452 KB Output is correct
12 Correct 18 ms 175524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 175452 KB Output is correct
2 Correct 18 ms 175524 KB Output is correct
3 Correct 18 ms 175452 KB Output is correct
4 Correct 18 ms 175332 KB Output is correct
5 Correct 19 ms 175452 KB Output is correct
6 Correct 18 ms 175448 KB Output is correct
7 Correct 18 ms 175452 KB Output is correct
8 Correct 18 ms 175452 KB Output is correct
9 Correct 18 ms 175500 KB Output is correct
10 Correct 19 ms 175444 KB Output is correct
11 Correct 19 ms 175452 KB Output is correct
12 Correct 18 ms 175524 KB Output is correct
13 Correct 21 ms 175452 KB Output is correct
14 Correct 32 ms 175452 KB Output is correct
15 Correct 21 ms 175452 KB Output is correct
16 Correct 30 ms 175556 KB Output is correct
17 Correct 24 ms 175512 KB Output is correct
18 Correct 22 ms 175452 KB Output is correct