結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー ぷらぷら
提出日時 2021-07-30 22:28:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,361 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 201,064 KB
実行使用メモリ 67,212 KB
最終ジャッジ日時 2023-10-14 05:41:45
合計ジャッジ時間 23,067 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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
5,516 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 2 ms
4,348 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,799 ms
66,940 KB
testcase_15 AC 1,887 ms
67,036 KB
testcase_16 AC 2,006 ms
67,128 KB
testcase_17 AC 1,618 ms
67,096 KB
testcase_18 AC 2,005 ms
67,212 KB
testcase_19 AC 1,637 ms
67,084 KB
testcase_20 AC 58 ms
65,652 KB
testcase_21 AC 74 ms
53,092 KB
testcase_22 AC 303 ms
65,132 KB
testcase_23 AC 1,808 ms
65,672 KB
testcase_24 AC 925 ms
65,276 KB
testcase_25 AC 198 ms
65,300 KB
testcase_26 WA -
testcase_27 AC 1,220 ms
66,612 KB
testcase_28 AC 640 ms
66,344 KB
testcase_29 AC 561 ms
65,840 KB
testcase_30 AC 667 ms
65,956 KB
testcase_31 AC 1,762 ms
66,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int 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