結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー monnumonnu
提出日時 2021-07-30 21:43:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 876 ms / 3,000 ms
コード長 1,458 bytes
コンパイル時間 4,177 ms
コンパイル使用メモリ 229,648 KB
実行使用メモリ 131,340 KB
最終ジャッジ日時 2023-10-14 04:02:24
合計ジャッジ時間 14,968 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 4 ms
4,356 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 4 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 789 ms
125,208 KB
testcase_15 AC 824 ms
131,340 KB
testcase_16 AC 870 ms
131,160 KB
testcase_17 AC 722 ms
131,068 KB
testcase_18 AC 876 ms
131,232 KB
testcase_19 AC 734 ms
131,068 KB
testcase_20 AC 179 ms
131,064 KB
testcase_21 AC 130 ms
115,444 KB
testcase_22 AC 298 ms
128,964 KB
testcase_23 AC 815 ms
129,012 KB
testcase_24 AC 514 ms
128,904 KB
testcase_25 AC 205 ms
127,800 KB
testcase_26 AC 52 ms
4,352 KB
testcase_27 AC 578 ms
95,700 KB
testcase_28 AC 325 ms
41,868 KB
testcase_29 AC 324 ms
42,656 KB
testcase_30 AC 346 ms
61,288 KB
testcase_31 AC 777 ms
94,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define MAX 100000
#define MOD 1000000007
#define INF 1000000000


int main(){
  int N;
  int K;
  cin>>N>>K;
  vector<int> c(9);
  for(int i=0;i<9;i++){
    cin>>c[i];
  }
  vector<int> res(N,1);
  for(int i=1;i<N;i++){
    res[i]=res[i-1]*10%K;
  }
  vector<vector<ll>> dp(1<<N,vector<ll>(K,0));
  dp[0][0]=1;
  int sum=0;
  for(int i=0;i<9;i++){
    if(c[i]==0){
      continue;
    }
    vector<int> bits;;
    for(int j=0;j<(1<<N);j++){
      int cnt=0;
      int bit=0;
      for(int k=0;k<N;k++){
        if(((j>>k)&1)==1){
          bit+=(1<<k);
          cnt++;
        }
      }
      if(cnt==c[i]){
        bits.push_back(bit);
      }
    }
    int n=bits.size();
    for(int j=0;j<n;j++){
      int x=0;
      for(int k=0;k<N;k++){
        if(((bits[j]>>k)&1)==1){
          x+=res[k];
        }
      }
      //cout<<x<<endl;
      x*=i+1;
      x%=K;
      //cout<<x<<endl;
      for(int k=0;k<(1<<N);k++){
        if((bits[j]&k)!=0){
          continue;
        }
        int cnt=0;
        for(int l=0;l<N;l++){
          if(((k>>l)&1)==1){
            cnt++;
          }
        }
        if(cnt!=sum){
          continue;
        }
        for(int l=0;l<K;l++){
          dp[bits[j]+k][(l+x)%K]+=dp[k][l];
        }
      }
    }
    sum+=c[i];
  }
  cout<<dp[(1<<N)-1][0]<<endl;
}
0