結果

問題 No.2178 Payable Magic Items
ユーザー nono00nono00
提出日時 2023-01-06 23:32:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 4,000 ms
コード長 1,615 bytes
コンパイル時間 2,146 ms
コンパイル使用メモリ 204,448 KB
実行使用メモリ 5,652 KB
最終ジャッジ日時 2023-08-21 08:23:30
合計ジャッジ時間 4,366 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 46 ms
4,616 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 47 ms
4,652 KB
testcase_06 AC 47 ms
4,564 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 47 ms
4,612 KB
testcase_09 AC 9 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 100 ms
5,360 KB
testcase_12 AC 99 ms
5,392 KB
testcase_13 AC 98 ms
5,416 KB
testcase_14 AC 98 ms
5,524 KB
testcase_15 AC 98 ms
5,652 KB
testcase_16 AC 98 ms
5,448 KB
testcase_17 AC 63 ms
4,904 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 20 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 84 ms
5,104 KB
testcase_25 AC 54 ms
4,568 KB
testcase_26 AC 25 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

/*
 *
 * 全ての性能において上回っている魔道具のみ残す
 *
 */

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> s(n);
    int sz = 1;
    for (int i = 0; i < k; i++) sz *= 5;
    vector<bool> result(sz, false);
    vector<bool> exist(sz, false);
    vector<int> use(sz, -1);

    for (int i = 0; i < n; i++) {
        string t;
        cin >> t;
        int state = 0;
        int now = 1;
        for (int j = 0; j < k; j++) {
            state += now * (t[j] - '0');
            now *= 5;
        }
        s[i] = state;
        exist[state] = true;
    }

    auto i2s = [&k](int state) {
        string t;
        for (int i = 0; i < k; i++) {
            t.push_back((char)((state % 5) + '0'));
            state /= 5;
        }
        return t;
    };

    function<bool(int)> f = [&](int state) -> bool {
        if (sz <= state) {
            return false;
        }
        if (use[state] != -1) {
            return result[state];
        }

        string t = i2s(state);
        bool flag = false;
        int now = 1;

        for (int i = 0; i < k; i++) {
            if (t[i] - '0' < 4) {
                flag |= f(state + now);
            }
            now *= 5;
        }

        result[state] = flag;
        use[state] = 0;

        if (!flag && exist[state]) {
            result[state] = true;
            use[state] = 1;
        }

        return result[state];
    };

    f(0);
    int ans = n;
    for (int i = 0; i < sz; i++) {
        if (use[i] == 1)
            ans--;
    }
    cout << ans << endl;
}
0