結果

問題 No.2178 Payable Magic Items
ユーザー srjywrdnprkt
提出日時 2023-05-05 17:12:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 109 ms / 4,000 ms
コード長 996 bytes
コンパイル時間 1,248 ms
コンパイル使用メモリ 108,580 KB
最終ジャッジ日時 2025-02-12 17:15:46
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

int main(){

    ll N, K, S, T, mx, u, ans=0;
    cin >> N >> K;
    string s;

    vector<ll> b(K+1);
    b[0] = 1;
    for (int i=1; i<=K; i++) b[i] = b[i-1] * 5;
    mx = b[K];
    vector<int> p(mx), q(mx);

    for (int i=0; i<N; i++){
        cin >> s;
        S = 0;
        for (int j=0; j<K; j++) S += b[j] * (s[j]-'0');
        p[S] = 1;
        q[S] = 1;
    }

    for (int i=mx-1; i>=0; i--){
        if (q[i] == 0) continue;
        for (int j=0; j<K; j++){
            u = (i / b[j]) % 5;
            if (u > 0){
                T = i - b[j];
                q[T] += 1;
            }
        }
    }

    for (int i=0; i<mx; i++){
        if (p[i] == 1 && q[i] > 1) ans++;
    }
    cout << ans << endl;

    return 0;
}
0