結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー simansiman
提出日時 2021-09-17 16:36:51
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 2,576 ms / 3,000 ms
コード長 1,228 bytes
コンパイル時間 4,529 ms
コンパイル使用メモリ 102,960 KB
実行使用メモリ 131,924 KB
最終ジャッジ日時 2023-09-12 04:23:58
合計ジャッジ時間 21,235 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
131,776 KB
testcase_01 AC 34 ms
131,780 KB
testcase_02 AC 33 ms
131,780 KB
testcase_03 AC 34 ms
131,764 KB
testcase_04 AC 32 ms
131,812 KB
testcase_05 AC 34 ms
131,712 KB
testcase_06 AC 34 ms
131,784 KB
testcase_07 AC 33 ms
131,700 KB
testcase_08 AC 32 ms
131,784 KB
testcase_09 AC 34 ms
131,904 KB
testcase_10 AC 32 ms
131,764 KB
testcase_11 AC 33 ms
131,852 KB
testcase_12 AC 33 ms
131,888 KB
testcase_13 AC 33 ms
131,888 KB
testcase_14 AC 534 ms
131,800 KB
testcase_15 AC 1,848 ms
131,924 KB
testcase_16 AC 2,576 ms
131,776 KB
testcase_17 AC 1,922 ms
131,784 KB
testcase_18 AC 2,366 ms
131,880 KB
testcase_19 AC 1,982 ms
131,804 KB
testcase_20 AC 266 ms
131,776 KB
testcase_21 AC 182 ms
131,876 KB
testcase_22 AC 295 ms
131,848 KB
testcase_23 AC 1,049 ms
131,780 KB
testcase_24 AC 483 ms
131,876 KB
testcase_25 AC 78 ms
131,808 KB
testcase_26 AC 41 ms
131,832 KB
testcase_27 AC 1,105 ms
131,796 KB
testcase_28 AC 842 ms
131,808 KB
testcase_29 AC 515 ms
131,760 KB
testcase_30 AC 731 ms
131,720 KB
testcase_31 AC 1,728 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;

  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 = pow(10, 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