結果

問題 No.2178 Payable Magic Items
ユーザー t98slider
提出日時 2023-01-07 00:10:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 49 ms / 4,000 ms
コード長 627 bytes
コンパイル時間 1,814 ms
コンパイル使用メモリ 169,240 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-14 17:30:31
合計ジャッジ時間 3,253 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int n, k;
vector<int> dp(390625), dp2(390625, -1);
int dfs(int cur){
    if(dp2[cur] != -1)return dp2[cur];
    dp2[cur] = dp[cur];
    for(int i = 0, d = 1; i < k; i++, d *= 5){
        if(cur / d % 5 < 4 && dfs(cur + d)){
            dp2[cur] = 1;
            dp[cur] = 0;
        }
    }
    return dp2[cur];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        dp[stoi(s, nullptr, 5)] = 1;
    }
    dfs(0);
    cout << n - accumulate(dp.begin(), dp.end(), 0) << endl;
}
0