結果
問題 | No.2178 Payable Magic Items |
ユーザー |
![]() |
提出日時 | 2023-01-06 21:53:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 162 ms / 4,000 ms |
コード長 | 867 bytes |
コンパイル時間 | 2,046 ms |
コンパイル使用メモリ | 199,368 KB |
最終ジャッジ日時 | 2025-02-09 23:50:56 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#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; }