結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー t98slidert98slider
提出日時 2023-07-23 20:13:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 189 ms / 3,000 ms
コード長 852 bytes
コンパイル時間 1,721 ms
コンパイル使用メモリ 173,716 KB
実行使用メモリ 131,264 KB
最終ジャッジ日時 2023-10-25 04:11:51
合計ジャッジ時間 4,868 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 153 ms
125,456 KB
testcase_15 AC 189 ms
131,264 KB
testcase_16 AC 186 ms
131,264 KB
testcase_17 AC 184 ms
131,264 KB
testcase_18 AC 183 ms
131,264 KB
testcase_19 AC 184 ms
131,264 KB
testcase_20 AC 102 ms
131,264 KB
testcase_21 AC 90 ms
115,688 KB
testcase_22 AC 100 ms
129,152 KB
testcase_23 AC 102 ms
129,152 KB
testcase_24 AC 100 ms
129,152 KB
testcase_25 AC 99 ms
127,832 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 106 ms
95,624 KB
testcase_28 AC 50 ms
42,032 KB
testcase_29 AC 39 ms
42,824 KB
testcase_30 AC 67 ms
61,304 KB
testcase_31 AC 97 ms
95,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, v, S = 0, cnt = 0;
    cin >> n >> k;
    vector<int> b(n);
    vector<vector<ll>> dp(1 << n, vector<ll>(k));
    for(int i = 1; i < 10; i++){
        cin >> v;
        for(int j = 0; j < v; j++){
            if(j) S |= 1 << j + cnt;
            b[j + cnt] = i;
        }
        cnt += v;
    }
    dp[0][0] = 1;
    for(int i = 0; i < (1 << n); i++){
        for(int j = 0; j < k; j++){
            if(dp[i][j] == 0) continue;
            for(int l = 0; l < n; l++){
                if(i >> l & 1) continue;
                if((S >> l & 1) && (~i >> (l - 1) & 1)) continue;
                dp[i | (1 << l)][(j * 10 + b[l]) % k] += dp[i][j];
            }
        }
    }
    cout << dp.back()[0] << '\n';
}
0