結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー boutarouboutarou
提出日時 2021-07-31 11:50:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,226 ms / 3,000 ms
コード長 1,340 bytes
コンパイル時間 5,092 ms
コンパイル使用メモリ 224,576 KB
実行使用メモリ 259,652 KB
最終ジャッジ日時 2023-10-14 14:49:47
合計ジャッジ時間 37,458 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 5 ms
4,348 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 5 ms
4,604 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2,069 ms
247,556 KB
testcase_15 AC 2,198 ms
259,652 KB
testcase_16 AC 2,226 ms
259,428 KB
testcase_17 AC 2,224 ms
259,308 KB
testcase_18 AC 2,194 ms
259,368 KB
testcase_19 AC 2,186 ms
259,412 KB
testcase_20 AC 2,110 ms
259,312 KB
testcase_21 AC 1,867 ms
228,228 KB
testcase_22 AC 2,079 ms
254,836 KB
testcase_23 AC 2,063 ms
254,860 KB
testcase_24 AC 2,067 ms
254,784 KB
testcase_25 AC 2,037 ms
252,276 KB
testcase_26 AC 22 ms
4,912 KB
testcase_27 AC 1,526 ms
187,764 KB
testcase_28 AC 586 ms
80,736 KB
testcase_29 AC 575 ms
82,256 KB
testcase_30 AC 887 ms
119,092 KB
testcase_31 AC 1,514 ms
186,756 KB
権限があれば一括ダウンロードができます

ソースコード

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<ll>> dp(1 << n, vector(K, (ll)0));
    dp[0][0] = 1;
    rep(i, n) {
        vector<vector<ll>> dp2(1 << n, vector(K, (ll)0));
        rep(j, 1 << n) {
            rep(k, K) {
                if (dp[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;
                    dp2[j | (1 << left)][(k * 10 + l) % K] += dp[j][k];
                }
            }
        }
        dp = dp2;
    }
    cout << dp[(1 << n) - 1][0] << endl;

    return 0;
}
0