結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー ぷらぷら
提出日時 2021-07-30 22:12:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,262 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 201,784 KB
実行使用メモリ 631,180 KB
最終ジャッジ日時 2023-10-14 05:09:22
合計ジャッジ時間 7,167 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,700 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 16 ms
30,188 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 11 ms
9,808 KB
testcase_10 AC 4 ms
9,908 KB
testcase_11 AC 6 ms
9,716 KB
testcase_12 AC 4 ms
5,716 KB
testcase_13 AC 4 ms
9,744 KB
testcase_14 MLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int dp[1 << 14][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][0] = 1;
    int cnt = 0;
    for(int i = 1; i <= 9; i++) {
        int a;
        cin >> a;
        for(int j = 0; j < a; j++) {
            for(int k = 0; k < (1 << N); k++) {
                if(__builtin_popcount(k) != cnt) {
                    continue;
                }
                for(int l = 0; l < N; l++) {
                    for(int o = 0; o < K; o++) {
                        for(int m = l; m < N; m++) {
                            if(1 & (k >> m)) {
                                continue;
                            }
                            if(j+1 == a) {
                                dp[k|(1 << m)][0][(o+tmp[m]*i)%K] += dp[k][l][o];
                            }
                            else if(m+1 < N) {
                                dp[k|(1 << m)][m+1][(o+tmp[m]*i)%K] += dp[k][l][o];
                            }
                        }
                    }
                }
            }
            cnt++;
        }
    }
    cout << dp[(1 << N)-1][0][0] << endl;
}
0