結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 23 ms
4,624 KB
testcase_04 AC 2 ms
4,352 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,352 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 3 ms
4,352 KB
testcase_13 WA -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 637 ms
387,412 KB
testcase_21 AC 613 ms
340,608 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 698 ms
380,544 KB
testcase_25 WA -
testcase_26 AC 22 ms
5,672 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
    }
    vector<bool> ok(1<<n);
    auto judge = [&](int s)->bool{
    int sum = 0;
        for(int i = 1; i <= 9; i++){
            for(int j = sum; j < sum+c[i]; j++){
                for(int k = j+1; k < sum+c[i]; k++){
                    if(s&(1<<j)){
                        if(!(s&(1<<k))) return false;
                    }
                }
            }
            sum += c[i];
        }
        return true;
    };
    for(int i = 0; i < 1<<n; i++) ok[i] = judge(i);
    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++){
            if(!ok[j]) continue;
            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;
                    int nxs = j+(1<<s);
                    if(ok[nxs]) dp[cur][nxs][nx] += dp[pre][j][l];
                }
            }
        }
    }
    cout << dp[n%2][(1<<n)-1][0] << endl;
}
0