답안 #1077211

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077211 2024-08-27T03:04:08 Z shiroboyy Kamenčići (COCI21_kamencici) C++14
70 / 70
120 ms 171740 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define endl "\n"
#define fi first
#define se second
#define SZ(x) (x).size()
#define ALL(x) (x).begin(), (x).end()
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(x) (1LL << (x))
#define rep(i, l, r) for (int i = (l), _r = (r); i <= _r; i++)
#define rev(i, r, l) for (int i = (r), _l = (l); i >= _l; i--)

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

template<class X, class Y> inline bool maximize(X &x, const Y &y) {return x < y ? x = y, 1 : 0;}
template<class X, class Y> inline bool minimize(X &x, const Y &y) {return x > y ? x = y, 1 : 0;}

const int MAX = 355;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

int num_pebble, num_red;
string pebble;
int cnt[MAX];
int f[MAX][MAX][MAX];

void input() {
    cin >> num_pebble >> num_red >> pebble;
}

void solve() {
    rep(i, 1, num_pebble) cnt[i] = cnt[i - 1] + (pebble[i] == 'C');

    rep(len, 1, num_pebble) {
        rep(u, 0, num_pebble - 1) {
            int c = u + len - 1;

            int total = 0;

            rep(i, 0, u - 1) total += (pebble[i] == 'C');
            rep(i, c + 1, num_pebble - 1) total += (pebble[i] == 'C');

            rep(k, 0, total) {
                int o = total - k;
                if (k >= num_red) f[u][c][k] = 0;
                else if (o >= num_red) f[u][c][k] = 1;
                else {
                    if (len == 1) {
                        f[u][c][k] = 0;
                        continue;
                    }
                    f[u][c][k] = (!f[u + 1][c][o] or !f[u][c - 1][o]);
                }
            }
        }
    }

    cout << (f[0][num_pebble - 1][0] ? "DA" : "NE") << endl;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #define task "kamencici"

    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }

    int test_case = 1; //cin >> test_case;
    while (test_case--) {
        input();
        solve();
    }

   cerr << "\nTime elapsed: " << clock() * 1.0 / CLOCKS_PER_SEC << " seconds" << endl;
}


Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 0 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 0 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 2 ms 3928 KB Output is correct
8 Correct 2 ms 3420 KB Output is correct
9 Correct 2 ms 3928 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 1 ms 3420 KB Output is correct
12 Correct 1 ms 3536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 0 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 2 ms 3928 KB Output is correct
8 Correct 2 ms 3420 KB Output is correct
9 Correct 2 ms 3928 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 1 ms 3420 KB Output is correct
12 Correct 1 ms 3536 KB Output is correct
13 Correct 91 ms 171740 KB Output is correct
14 Correct 107 ms 170580 KB Output is correct
15 Correct 81 ms 154448 KB Output is correct
16 Correct 97 ms 168612 KB Output is correct
17 Correct 120 ms 169808 KB Output is correct
18 Correct 94 ms 168768 KB Output is correct