結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー H3PO4H3PO4
提出日時 2023-10-15 18:25:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 594 ms / 3,000 ms
コード長 909 bytes
コンパイル時間 933 ms
コンパイル使用メモリ 78,324 KB
実行使用メモリ 131,200 KB
最終ジャッジ日時 2023-10-15 18:25:51
合計ジャッジ時間 10,609 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 3 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 542 ms
125,208 KB
testcase_15 AC 581 ms
131,068 KB
testcase_16 AC 569 ms
131,132 KB
testcase_17 AC 569 ms
131,024 KB
testcase_18 AC 570 ms
131,136 KB
testcase_19 AC 594 ms
131,200 KB
testcase_20 AC 565 ms
131,188 KB
testcase_21 AC 503 ms
115,500 KB
testcase_22 AC 556 ms
128,948 KB
testcase_23 AC 555 ms
129,028 KB
testcase_24 AC 561 ms
129,032 KB
testcase_25 AC 553 ms
127,768 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 428 ms
95,560 KB
testcase_28 AC 171 ms
41,784 KB
testcase_29 AC 174 ms
42,700 KB
testcase_30 AC 255 ms
61,168 KB
testcase_31 AC 431 ms
94,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

int main() {
    int N, K;
    std::cin >> N >> K;
    std::vector<int> X(N, 0);
    int ct = 0;
    int div = 1;
    for (int i = 1; i < 10; i++) {
        int c;
        std::cin >> c;
        for (int j = 1; j <= c; j++) {
            div *= j;
        }
        for (int j = 0; j < c; j++) {
            X.at(ct) = i;
            ct++;
        }
    }

    std::vector<std::vector<long>> A(1 << N, std::vector<long>(K));
    A.at(0).at(0) = 1;

    for (int b = 0; b < 1 << N; b++) {
        for (int i = 0; i < N; i++) {
            if (!(b & (1 << i))) {
                int c = b | (1 << i);
                for (int k = 0; k < K; k++) {
                    int next_k = (k * 10 + X.at(i)) % K;
                    A.at(c).at(next_k) += A.at(b).at(k);
                }
            }
        }
    }
    std::cout << A.at((1 << N) - 1).at(0) / div << std::endl;
}
0