結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー milanis48663220milanis48663220
提出日時 2021-07-30 21:37:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,148 bytes
コンパイル時間 1,267 ms
コンパイル使用メモリ 125,288 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-10-14 03:48:37
合計ジャッジ時間 6,413 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,704 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 15 ms
4,552 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 7 ms
4,352 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 TLE -
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 <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;


template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, k; cin >> n >> k;
    vector<int> c(10);
    for(int i = 1; i <= 9; i++) cin >> c[i];
    vector<int> v;
    for(int i = 1; i <= 9; i++){
        for(int j = 0; j < c[i]; j++) v.push_back(i);
    }
    auto dp = vec3d<ll>(2, 1<<n, k, 0);
    dp[0][0][0] = 1;
    vector<int> pow10(n);
    pow10[0] = 1%k;
    for(int i = 1; i < n; i++){
        pow10[i] = (pow10[i-1]*10)%k;
    }
    for(int i = 0; i < n; i++){
        int cur = (i+1)%2;
        int pre = cur^1;
        // cout << cur << ' ' << pre << endl;
        for(int j = 0; j < 1<<n; j++){
            for(int l = 0; l < k; l++){
                dp[cur][j][l] = 0;
            }
        }
        for(int j = 0; j < 1<<n; j++){
            vector<int> u;
            for(int l = 0; l < n; l++){
                if(j&(1<<l)) continue;
                u.push_back(l);
            }
            for(int l = 0; l < k; l++){
                for(int s: u){
                    int nx = (l+pow10[s]*v[i])%k;
                    dp[cur][j+(1<<s)][nx] += dp[pre][j][l];
                }
            }
        }
    }
    cout << dp[n%2][(1<<n)-1][0] << endl;
}
0