結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー sten_sansten_san
提出日時 2021-07-30 22:09:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,537 bytes
コンパイル時間 1,941 ms
コンパイル使用メモリ 202,140 KB
実行使用メモリ 131,620 KB
最終ジャッジ日時 2023-10-14 05:01:22
合計ジャッジ時間 16,301 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,692 KB
testcase_01 AC 2 ms
5,432 KB
testcase_02 AC 2 ms
5,492 KB
testcase_03 AC 5 ms
9,504 KB
testcase_04 AC 2 ms
5,408 KB
testcase_05 AC 2 ms
5,508 KB
testcase_06 AC 2 ms
5,420 KB
testcase_07 AC 2 ms
5,476 KB
testcase_08 AC 2 ms
5,452 KB
testcase_09 AC 5 ms
5,900 KB
testcase_10 AC 3 ms
5,904 KB
testcase_11 AC 3 ms
5,964 KB
testcase_12 AC 2 ms
5,716 KB
testcase_13 AC 2 ms
5,900 KB
testcase_14 AC 858 ms
131,360 KB
testcase_15 AC 905 ms
131,372 KB
testcase_16 AC 903 ms
131,360 KB
testcase_17 AC 896 ms
131,496 KB
testcase_18 AC 899 ms
131,352 KB
testcase_19 AC 907 ms
131,620 KB
testcase_20 AC 891 ms
131,508 KB
testcase_21 AC 803 ms
131,600 KB
testcase_22 AC 893 ms
131,364 KB
testcase_23 AC 899 ms
131,412 KB
testcase_24 AC 891 ms
131,428 KB
testcase_25 AC 886 ms
131,484 KB
testcase_26 WA -
testcase_27 AC 675 ms
131,384 KB
testcase_28 AC 312 ms
131,600 KB
testcase_29 AC 313 ms
131,428 KB
testcase_30 AC 443 ms
131,364 KB
testcase_31 AC 677 ms
131,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct iofast_t {
    iofast_t() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} iofast;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

template <typename T, typename Compare = less<T>>
T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); }
template <typename T, typename Compare = less<T>>
T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); }

constexpr int lim = 14;

uint32_t dp[2][1 << lim][1000];

int main() {
    int n, k; cin >> n >> k;

    auto [c, count] = [&] {
        array<int, lim> c = {};
        array<int, 9> count = {};

        auto iter = begin(c);
        for (int i = 1; i <= 9; ++i) {
            int v; cin >> v;
            count[i - 1] = v;
            while (v--) {
                *iter++ = i;
            }
        }

        return make_tuple(c, count);
    }();

    auto pow = [&] {
        array<int, lim> pow = {};

        pow[0] = 1;
        for (int i = 1; i < n; ++i) {
            pow[i] = (pow[i - 1] * 10) % k;
        }

        return pow;
    }();

    auto popcount = [](auto x) {
        return bitset<sizeof(x) * CHAR_BIT>(x).count();
    };

    bool turn = false;

    dp[turn][0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int to = 0; to < (1 << n); ++to) {
            if (i != popcount(to)) {
                continue;
            }

            for (int j = 0; j < n; ++j) {
                if (!(to & (1 << j))) {
                    continue;
                }

                int from = to ^ (1 << j);
                for (int r = 0; r < k; ++r) {
                    dp[!turn][to][r] += dp[turn][from][(k + (r - (pow[i - 1] * c[j])) % k) % k];
                }
            }
        }

        turn = !turn;
        for (int j = 0; j < (1 << n); ++j) {
            for (int r = 0; r < k; ++r) {
                dp[!turn][j][r] = 0;
            }
        }
    }

    auto ans = dp[turn][(1 << n) - 1][0];

    for (int i = 0; i < 9; ++i) {
        int64_t f = 1;
        for (int j = 1; j <= count[i]; ++j) {
            f *= j;
        }
        ans /= f;
    }

    cout << ans << endl;
}

0