結果
問題 | No.2302 Carry X Times |
ユーザー |
![]() |
提出日時 | 2024-11-08 01:13:55 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 1,482 bytes |
コンパイル時間 | 2,580 ms |
コンパイル使用メモリ | 218,408 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-08 01:13:59 |
合計ジャッジ時間 | 3,803 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios_base::sync_with_stdio(false);cin.tie(nullptr);}#include <atcoder/modint>using mint = atcoder::modint998244353;void solve() {long long N;int x;cin >> N >> x;vector<int> n;while (N) {n.push_back(N % 10);N /= 10;}reverse(n.begin(), n.end());int l = n.size();vector dp(l + 1, vector(2, vector(2, vector(x + 1, vector<mint>(2)))));dp[l][1][1][0][0] = 1;for (int i = l - 1; i >= 0; i--) {for (int smaller_a = 0; smaller_a < 2; smaller_a++) {for (int smaller_b = 0; smaller_b < 2; smaller_b++) {for (int j = 0; j <= x; j++) {for (int carry = 0; carry < 2; carry++) {for (int a = 0; a < 10; a++) {for (int b = 0; b < 10; b++) {int smaller_a_next =(a == n[i]) ? smaller_a : (a < n[i]);int smaller_b_next =(b == n[i]) ? smaller_b : (b < n[i]);if ((a + b + carry) >= 10) {if (j == x) {continue;}dp[i][smaller_a_next][smaller_b_next][j + 1][1] += dp[i + 1][smaller_a][smaller_b][j][carry];} else {dp[i][smaller_a_next][smaller_b_next][j][0] += dp[i + 1][smaller_a][smaller_b][j][carry];}}}}}}}}mint ans = dp[0][1][1][x][0] + dp[0][1][1][x][1];cout << ans.val() << "\n";}int main() {fast_io();int t;cin >> t;for (; t--;) {solve();}}