結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー boutarouboutarou
提出日時 2021-07-31 11:42:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,515 bytes
コンパイル時間 3,576 ms
コンパイル使用メモリ 222,552 KB
実行使用メモリ 813,284 KB
最終ジャッジ日時 2023-10-14 14:48:57
合計ジャッジ時間 6,367 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 7 ms
8,528 KB
testcase_04 AC 2 ms
4,356 KB
testcase_05 AC 1 ms
4,356 KB
testcase_06 AC 1 ms
4,356 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 8 ms
9,848 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 4 ms
5,380 KB
testcase_12 AC 2 ms
4,684 KB
testcase_13 AC 1 ms
4,352 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 #

#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < int(n); i++)
using ll = long long;
using P = pair<int, int>;

// i桁まで決定されていて、数字の残りがxで、数字 % K == jとなるものの通り数

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n, K; cin >> n >> K;
    vector<int> c(10);
    rep(i, 9) cin >> c[i + 1];
    vector<int> sum(11);
    rep(i, 10) sum[i + 1] = sum[i] + c[i];
    vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(1 << n, vector<ll>(K, 0)));
    dp[0][0][0] = 1;
    rep(i, n) {
        rep(j, 1 << n) {
            rep(k, K) {
                if (dp[i][j][k] == 0) continue;
                for (int l = 1; l <= 9; l++) {
                    int left = -1;
                    for (int pos = sum[l]; pos < sum[l + 1]; pos++) {
                        if (!(j >> pos & 1)) {
                            left = pos; break;
                        }
                    }
                    if (left == -1) continue;
                    dp[i + 1][j | (1 << left)][(k * 10 + l) % K] += dp[i][j][k];
                }
            }
        }
    }

    rep(i, n + 1) {
        rep(j, 1 << n) {
            rep(k, K) {
                // cout << "{" << i << " " << j << " " << k << "}" << " " << dp[i][j][k] << endl;
            }
        }
    }
    cout << dp[n][(1 << n) - 1][0] << endl;

    return 0;
}
0