結果
| 問題 |
No.1631 Sorting Integers (Multiple of K) Easy
|
| コンテスト | |
| ユーザー |
eve__fuyuki
|
| 提出日時 | 2024-05-08 14:21:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,532 ms / 3,000 ms |
| コード長 | 1,179 bytes |
| コンパイル時間 | 1,977 ms |
| コンパイル使用メモリ | 200,052 KB |
| 最終ジャッジ日時 | 2025-02-21 11:45:12 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
fast_io();
int n, k;
cin >> n >> k;
vector<int> a;
vector<int> c(10);
for (int i = 1; i <= 9; i++) {
cin >> c[i];
for (int j = 0; j < c[i]; j++) {
a.push_back(i);
}
}
long long p10[20];
p10[0] = 1;
for (int i = 1; i < 20; i++) {
p10[i] = p10[i - 1] * 10 % k;
}
vector<vector<long long>> dp(1 << n, vector<long long>(k));
dp[0][0] = 1;
for (int st = 0; st < (1 << n); st++) {
int next_i = __builtin_popcount(st);
for (int j = 0; j < k; j++) {
for (int l = 0; l < n; l++) {
if (st & (1 << l)) {
continue;
}
int next_j = (j + p10[l] * a[next_i]) % k;
dp[st | (1 << l)][next_j] += dp[st][j];
}
}
}
long long ans = dp.back()[0];
for (int i = 1; i < 10; i++) {
for (int j = 2; j <= c[i]; j++) {
assert(ans % j == 0);
ans /= j;
}
}
cout << ans << endl;
}
eve__fuyuki