結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー simansiman
提出日時 2021-09-17 16:40:14
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 678 ms / 3,000 ms
コード長 1,315 bytes
コンパイル時間 1,311 ms
コンパイル使用メモリ 104,944 KB
実行使用メモリ 131,908 KB
最終ジャッジ日時 2023-09-12 04:24:07
合計ジャッジ時間 8,103 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
131,780 KB
testcase_01 AC 35 ms
131,876 KB
testcase_02 AC 33 ms
131,720 KB
testcase_03 AC 33 ms
131,728 KB
testcase_04 AC 33 ms
131,820 KB
testcase_05 AC 33 ms
131,752 KB
testcase_06 AC 32 ms
131,728 KB
testcase_07 AC 34 ms
131,656 KB
testcase_08 AC 34 ms
131,728 KB
testcase_09 AC 33 ms
131,848 KB
testcase_10 AC 33 ms
131,864 KB
testcase_11 AC 34 ms
131,876 KB
testcase_12 AC 33 ms
131,908 KB
testcase_13 AC 34 ms
131,784 KB
testcase_14 AC 189 ms
131,828 KB
testcase_15 AC 517 ms
131,868 KB
testcase_16 AC 678 ms
131,868 KB
testcase_17 AC 531 ms
131,788 KB
testcase_18 AC 638 ms
131,780 KB
testcase_19 AC 553 ms
131,744 KB
testcase_20 AC 128 ms
131,892 KB
testcase_21 AC 102 ms
131,864 KB
testcase_22 AC 135 ms
131,788 KB
testcase_23 AC 337 ms
131,740 KB
testcase_24 AC 191 ms
131,788 KB
testcase_25 AC 61 ms
131,792 KB
testcase_26 AC 38 ms
131,888 KB
testcase_27 AC 329 ms
131,788 KB
testcase_28 AC 246 ms
131,788 KB
testcase_29 AC 170 ms
131,884 KB
testcase_30 AC 230 ms
131,724 KB
testcase_31 AC 473 ms
131,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

ll dp[1 << 14][1001];

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> nums;
  memset(dp, 0, sizeof(dp));
  int div = 1;

  int cnt;
  for (int i = 1; i <= 9; ++i) {
    cin >> cnt;
    int v = 1;

    for (int j = 1; j <= cnt; ++j) {
      v *= j;
    }

    div *= v;

    for (int j = 0; j < cnt; ++j) {
      nums.push_back(i);
    }
  }

  dp[0][0] = 1;
  vector<ll> bases;
  for (int i = 0; i < N; ++i) {
    bases.push_back(pow(10, i));
  }

  for (int i = 0; i < N; ++i) {
    int num = nums[i];

    for (int mask = 0; mask < (1 << N); ++mask) {
      if (__builtin_popcount(mask) != i) continue;

      for (int k = 0; k < K; ++k) {
        if (dp[mask][k] == 0) continue;

        for (int j = 0; j < N; ++j) {
          if (mask >> j & 1) continue;

          ll base = bases[j];
          int nmask = mask | (1 << j);
          int nk = (k + num * base) % K;
          dp[nmask][nk] += dp[mask][k];
          // fprintf(stderr, "i: %d, update: %d\n", i, nk);
        }
      }
    }
  }

  cout << dp[(1 << N) - 1][0] / div << endl;

  return 0;
}
0