結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー simansiman
提出日時 2021-09-17 16:14:26
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,229 bytes
コンパイル時間 3,964 ms
コンパイル使用メモリ 105,804 KB
実行使用メモリ 131,892 KB
最終ジャッジ日時 2023-09-12 04:23:31
合計ジャッジ時間 25,454 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
131,820 KB
testcase_01 AC 45 ms
131,784 KB
testcase_02 AC 44 ms
131,788 KB
testcase_03 AC 46 ms
131,856 KB
testcase_04 AC 44 ms
131,772 KB
testcase_05 AC 45 ms
131,748 KB
testcase_06 AC 40 ms
131,724 KB
testcase_07 AC 40 ms
131,760 KB
testcase_08 AC 40 ms
131,804 KB
testcase_09 AC 41 ms
131,784 KB
testcase_10 AC 38 ms
131,852 KB
testcase_11 AC 41 ms
131,856 KB
testcase_12 AC 34 ms
131,776 KB
testcase_13 AC 39 ms
131,860 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 263 ms
131,860 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 41 ms
131,824 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

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;

          int 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