結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー nawawannawawan
提出日時 2021-07-30 21:48:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,451 ms / 3,000 ms
コード長 3,210 bytes
コンパイル時間 1,729 ms
コンパイル使用メモリ 172,440 KB
実行使用メモリ 131,320 KB
最終ジャッジ日時 2023-10-14 04:16:47
合計ジャッジ時間 38,094 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 8 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 9 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 4 ms
4,352 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2,331 ms
125,380 KB
testcase_15 AC 2,450 ms
131,000 KB
testcase_16 AC 2,444 ms
130,996 KB
testcase_17 AC 2,449 ms
131,000 KB
testcase_18 AC 2,441 ms
131,048 KB
testcase_19 AC 2,451 ms
131,320 KB
testcase_20 AC 2,446 ms
131,068 KB
testcase_21 AC 2,156 ms
115,420 KB
testcase_22 AC 2,405 ms
128,944 KB
testcase_23 AC 2,410 ms
128,972 KB
testcase_24 AC 2,401 ms
128,888 KB
testcase_25 AC 2,382 ms
127,728 KB
testcase_26 AC 8 ms
4,352 KB
testcase_27 AC 1,758 ms
95,516 KB
testcase_28 AC 742 ms
41,896 KB
testcase_29 AC 754 ms
42,620 KB
testcase_30 AC 1,108 ms
61,120 KB
testcase_31 AC 1,758 ms
94,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
struct modint{
    long long val;
    modint(): val(0) {}
    modint(long long x){
        if(x < 0) val = x % mod() + mod();
        else val = x % mod();
    }
    modint(const modint &t){
        val = t.val;
    }
    static int &mod(){
        static int m = 0;
        return m;
    }
    static void set_mod(int md){
        mod() = md;
    }
    modint& operator =(const modint m){
        val = m.val;
        return *this;
    }
    modint operator -(){
        return modint(-val);
    }
    modint& operator-=(const modint &m){
        val -= m.val;
        if(val < 0) val += mod();
        return *this;
    }
    modint& operator+=(const modint &m){
        val += m.val;
        if(val >= mod()) val -= mod();
        return *this;
    }
    modint& operator*=(const modint &m){
        val *= m.val;
        val %= mod();
        return *this;
    }
    modint& operator/=(modint m){
        *this *= m.inv();
        return *this;
    }
    modint inv(){
        long long x = 1, y = 0;
        long long a = val, b = mod();
        while(b != 0){
            long long t = a / b;
            a -= t * b;
            x -= t * y;
            swap(a, b);
            swap(x, y);
        }
        x %= mod();
        if(x < 0) x += mod();
        return modint(x);
    }
    modint pow(long long k){
        long long res = 1;
        long long v = val;
        while(k > 0){
            if(k & 1) res = res * v % mod();
            v = v * v % mod();
            k >>= 1;
        }
        return modint(res);
    }
    bool operator==(const modint &m){
        return val == m.val;
    }
    modint operator+(const modint &m){
        return modint(*this) += m;
    }
    modint operator-(const modint &m){
        return modint(*this) -= m;
    }
    modint operator*(const modint &m){
        return modint(*this) *= m;
    }
    modint operator/(const modint &m){
        return modint(*this) /= m;
    }
    bool operator!=(const modint &m){
        return modint(*this).val != m.val;
    }
    bool operator!=(const int &m){
        return modint(*this).val != m;
    }
};
using mint = modint;
int main(){
    int N, K;
    cin >> N >> K;
    modint::set_mod(K); 
    vector<int> c(9);
    for(int i = 0; i < 9; i++) cin >> c[i];
    vector<mint> ten(N + 1);
    ten[0] = 1;
    for(int i = 0; i < N; i++) ten[i + 1] = ten[i] * 10;
    vector<vector<long long>> dp((1 << N), vector<long long>(K));
    dp[0][0] = 1;
    vector<int> num(N);
    int id = 0;
    for(int i = 0; i < 9; i++){
        for(int j = 0; j < c[i]; j++){
            num[id] = i + 1;
            id++;
        }
    }
    for(int bit = 0; bit < (1 << N); bit++){
        int cnt = __builtin_popcount(bit);
        for(int j = 0; j < N; j++){
            if((bit & (1 << j)) == 0){
                for(int k = 0; k < K; k++){
                    mint te = ten[N - 1 - cnt] * num[j] + k;
                    dp[bit ^ (1 << j)][te.val] += dp[bit][k];
                }
            }
        }
    }
    for(int i = 0; i < 9; i++){
        for(int j = 0; j < c[i]; j++){
            dp[(1 << N) - 1][0] /= (j + 1);
        }
    }
    cout << dp[(1 << N) - 1][0] << endl;
}
0