結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー playrollerplayroller
提出日時 2021-08-29 15:16:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,174 ms / 3,000 ms
コード長 1,364 bytes
コンパイル時間 1,746 ms
コンパイル使用メモリ 175,128 KB
実行使用メモリ 131,328 KB
最終ジャッジ日時 2024-05-01 22:32:16
合計ジャッジ時間 18,965 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 4 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1,113 ms
125,440 KB
testcase_15 AC 1,164 ms
131,328 KB
testcase_16 AC 1,163 ms
131,328 KB
testcase_17 AC 1,165 ms
131,328 KB
testcase_18 AC 1,174 ms
131,328 KB
testcase_19 AC 1,167 ms
131,328 KB
testcase_20 AC 1,156 ms
131,328 KB
testcase_21 AC 1,021 ms
115,712 KB
testcase_22 AC 1,174 ms
129,024 KB
testcase_23 AC 1,135 ms
129,024 KB
testcase_24 AC 1,152 ms
129,024 KB
testcase_25 AC 1,156 ms
127,744 KB
testcase_26 AC 7 ms
6,940 KB
testcase_27 AC 843 ms
95,488 KB
testcase_28 AC 352 ms
41,856 KB
testcase_29 AC 363 ms
42,752 KB
testcase_30 AC 522 ms
61,184 KB
testcase_31 AC 856 ms
94,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 998244353;
 
using i64 = long long;
using pi = pair<int, int>;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

i64 pow(i64 x, i64 n, i64 mod) {
  i64 ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, K;
  cin >> n >> K;
  vt<int> c(9);
  vt<int> a;
  rep(i, 0, 9) {
    cin >> c[i];
    rep(j, 0, c[i]) a.push_back(i + 1);
  }

  vvt<i64> dp(1 << n, vt<i64>(K, 0));
  dp[0][0] = 1;
  rep(bit, 0, 1 << n) {
    int cnt = 0;
    rep(j, 0, n) {
      if(bit & (1 << j)) cnt++;
    }
    int num = pow(10, cnt, K);
    rep(j, 0, n) {
      if(bit & (1 << j)) continue;
      for(i64 k = 0; k < K; ++k) {
        dp[bit | (1 <<  j)][(k + a[j] * num) % K] += dp[bit][k];
      }
    }
  }

  i64 ans = dp[(1 << n) - 1][0];
  rep(i, 0, 9) {
    rep(j, 0, c[i]) {
      ans /= (j + 1);
    }
  }
  cout << ans << endl;
}
0