結果
問題 | No.1631 Sorting Integers (Multiple of K) Easy |
ユーザー |
|
提出日時 | 2021-08-29 15:16:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,295 ms / 3,000 ms |
コード長 | 1,364 bytes |
コンパイル時間 | 1,965 ms |
コンパイル使用メモリ | 174,348 KB |
実行使用メモリ | 131,328 KB |
最終ジャッジ日時 | 2024-11-22 05:48:49 |
合計ジャッジ時間 | 21,364 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 28 |
ソースコード
#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; }