結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー ぷらぷら
提出日時 2021-07-30 22:11:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,333 bytes
コンパイル時間 1,960 ms
コンパイル使用メモリ 206,852 KB
実行使用メモリ 814,364 KB
最終ジャッジ日時 2023-10-14 05:07:04
合計ジャッジ時間 4,436 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 15 ms
7,980 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 15 ms
8,264 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 6 ms
5,008 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 2 ms
4,348 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 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;
    }
    vector<vector<vector<long long>>>dp(1 << N,vector<vector<long long>>(N,vector<long long>(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