結果
| 問題 | No.1631 Sorting Integers (Multiple of K) Easy |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-31 11:18:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,177 bytes |
| 記録 | |
| コンパイル時間 | 2,464 ms |
| コンパイル使用メモリ | 208,020 KB |
| 最終ジャッジ日時 | 2025-01-23 13:00:01 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 TLE * 6 |
ソースコード
#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桁まで決定されていて、数字の残りがvector<int> aで、数字 % 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<map<pair<vector<int>, int>, ll>> dp(n + 1);
dp[0][{c, 0}] = 1;
rep(i, n) {
for (auto elem : dp[i]) {
vector<int> left = elem.first.first;
int mod = elem.first.second;
ll val = elem.second;
for (int j = 1; j <= 9; j++) {
if (left[j] == 0) continue;
int nmod = (mod * 10 + j) % K;
left[j]--;
dp[i + 1][{left, nmod}] += val;
left[j]++;
}
}
}
ll ans = 0;
for (auto elem : dp[n]) {
vector<int> left = elem.first.first;
int mod = elem.first.second;
ll val = elem.second;
if (mod == 0) ans += val;
}
cout << ans << endl;
return 0;
}