結果
問題 |
No.1631 Sorting Integers (Multiple of K) Easy
|
ユーザー |
|
提出日時 | 2021-07-31 11:50:00 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,024 ms / 3,000 ms |
コード長 | 1,340 bytes |
コンパイル時間 | 10,815 ms |
コンパイル使用メモリ | 287,896 KB |
最終ジャッジ日時 | 2025-01-23 13:03:07 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 28 |
ソースコード
#pragma GCC target ("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < int(n); i++) using ll = long long; using P = pair<int, int>; // i桁まで決定されていて、数字の残りがxで、数字 % K == jとなるものの通り数 int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, K; cin >> n >> K; vector<int> c(10); rep(i, 9) cin >> c[i + 1]; vector<int> sum(11); rep(i, 10) sum[i + 1] = sum[i] + c[i]; vector<vector<ll>> dp(1 << n, vector(K, (ll)0)); dp[0][0] = 1; rep(i, n) { vector<vector<ll>> dp2(1 << n, vector(K, (ll)0)); rep(j, 1 << n) { rep(k, K) { if (dp[j][k] == 0) continue; for (int l = 1; l <= 9; l++) { int left = -1; for (int pos = sum[l]; pos < sum[l + 1]; pos++) { if (!(j >> pos & 1)) { left = pos; break; } } if (left == -1) continue; dp2[j | (1 << left)][(k * 10 + l) % K] += dp[j][k]; } } } dp = dp2; } cout << dp[(1 << n) - 1][0] << endl; return 0; }