結果
問題 | No.1631 Sorting Integers (Multiple of K) Easy |
ユーザー |
|
提出日時 | 2021-08-29 15:01:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,354 bytes |
コンパイル時間 | 2,062 ms |
コンパイル使用メモリ | 172,888 KB |
実行使用メモリ | 72,832 KB |
最終ジャッジ日時 | 2024-11-22 05:44:09 |
合計ジャッジ時間 | 67,796 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 WA * 1 TLE * 15 |
ソースコード
#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<int> dp(1 << n, vt<int>(K, 0)); dp[0][0] = 1; rep(bit, 0, 1 << n) { int cnt = 0; rep(j, 0, n) { if(bit & (1 << j)) cnt++; } rep(j, 0, n) { if(!(bit & (1 << j))) { for(i64 k = 0; k < K; ++k) { dp[bit | (1 << j)][(k + a[j] * pow(10, cnt, K)) % K] += dp[bit][k]; } } } } int ans = dp[(1 << n) - 1][0]; rep(i, 0, 9) { rep(j, 0, c[i]) { ans /= (j + 1); } } cout << ans << endl; }