結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー ぷらぷら
提出日時 2021-07-30 22:29:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,000 ms / 3,000 ms
コード長 1,367 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 201,128 KB
実行使用メモリ 130,888 KB
最終ジャッジ日時 2023-10-14 05:44:59
合計ジャッジ時間 22,837 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 7 ms
6,728 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,356 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 5 ms
4,372 KB
testcase_10 AC 2 ms
4,356 KB
testcase_11 AC 3 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 1,795 ms
130,440 KB
testcase_15 AC 1,876 ms
130,552 KB
testcase_16 AC 1,994 ms
130,748 KB
testcase_17 AC 1,614 ms
130,480 KB
testcase_18 AC 2,000 ms
130,500 KB
testcase_19 AC 1,634 ms
130,888 KB
testcase_20 AC 70 ms
126,888 KB
testcase_21 AC 78 ms
77,796 KB
testcase_22 AC 311 ms
128,492 KB
testcase_23 AC 1,807 ms
129,252 KB
testcase_24 AC 927 ms
128,820 KB
testcase_25 AC 207 ms
129,196 KB
testcase_26 AC 49 ms
129,180 KB
testcase_27 AC 1,221 ms
130,208 KB
testcase_28 AC 639 ms
129,572 KB
testcase_29 AC 564 ms
128,964 KB
testcase_30 AC 672 ms
129,544 KB
testcase_31 AC 1,763 ms
130,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long dp[1 << 14][1000];

int main() {
    int N,K;
    cin >> N >> K;
    vector<int>tmp(N);
    tmp[0] = 1%K;
    for(int i = 1; i < N; i++) {
        tmp[i] = tmp[i-1]*10%K;
    }
    dp[0][0] = 1;
    int cnt = 0;
    for(int i = 1; i <= 9; i++) {
        int a;
        cin >> a;
        cnt += a;
        if(a == 0) {
            continue;
        }
        for(int j = 0; j < (1 << N); j++) {
            if(__builtin_popcount(j) != cnt) {
                continue;
            }
            vector<int>res;
            for(int k = 0; k < N; k++) {
                if(1 & (j >> k)) {
                    res.push_back(k);
                }
            }
            for(int k = 0; k < (1 << res.size()); k++) {
                if(__builtin_popcount(k) != a) {
                    continue;
                }
                long long sum = 0;
                int old = j;
                for(int l = 0; l < res.size(); l++) {
                    if(1 & (k >> l)) {
                        old -= (1 << res[l]);
                        sum += tmp[res[l]]*i;
                    }
                }
                sum %= K;
                for(int l = 0; l < K; l++) {
                    dp[j][(l+sum)%K] += dp[old][l];
                }
            }
        }
    }
    cout << dp[(1 << N)-1][0] << endl;
}
0