結果

問題 No.2178 Payable Magic Items
ユーザー ぷらぷら
提出日時 2023-01-06 21:53:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 168 ms / 4,000 ms
コード長 867 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 204,360 KB
実行使用メモリ 19,636 KB
最終ジャッジ日時 2023-08-21 08:15:05
合計ジャッジ時間 4,531 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 33 ms
9,940 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 11 ms
4,376 KB
testcase_06 AC 15 ms
5,796 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 14 ms
8,924 KB
testcase_09 AC 4 ms
4,416 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 168 ms
19,316 KB
testcase_12 AC 152 ms
19,336 KB
testcase_13 AC 148 ms
19,636 KB
testcase_14 AC 153 ms
19,320 KB
testcase_15 AC 151 ms
19,320 KB
testcase_16 AC 147 ms
19,440 KB
testcase_17 AC 59 ms
12,980 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 23 ms
6,788 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 102 ms
16,616 KB
testcase_25 AC 42 ms
11,176 KB
testcase_26 AC 33 ms
7,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int dp[2002002];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,K;
    cin >> N >> K;
    set<int>st;
    for(int i = 0; i < N; i++) {
        string S;
        cin >> S;
        int tmp = 0,res = 1;
        for(int j = 0; j < K; j++) {
            tmp += res*(S[j]-'0'+1);
            res *= 6;
        }
        st.insert(tmp);
    }
    int p = 1;
    for(int j = 0; j < K; j++) p *= 6;
    int ans = N;
    for(int i = p-1; i >= 0; i--) {
        if(dp[i] == 0 && st.count(i)) {
            ans--;
            dp[i] = 1;
        }
        if(dp[i] == 0) continue;
        int d = i,tmp = 1;
        for(int j = 0; j < K; j++) {
            if(d%6 != 0) {
                dp[i-tmp] = 1;
            }
            tmp *= 6;
            d /= 6;
        }
    }
    cout << ans << endl;
}
0