結果

問題 No.2302 Carry X Times
ユーザー 沙耶花沙耶花
提出日時 2023-05-12 21:43:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,151 bytes
コンパイル時間 4,295 ms
コンパイル使用メモリ 272,664 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 11:29:37
合計ジャッジ時間 5,165 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001



int main(){
	
	int _t;
	cin>>_t;
	rep(_,_t){
		long long n,x;
		cin>>n>>x;
		string s = to_string(n);
		reverse(s.begin(),s.end());
		s.push_back('0');
		vector dp(2,vector(2,vector(2,vector<mint>(x+1))));
		dp[0][0][0][0] = 1;
		rep(i,s.size()){
			int xx = s[i]-'0';
			vector ndp(2,vector(2,vector(2,vector<mint>(x+1))));
			rep(j,2){
				rep(k,2){
					rep(m,2){
						rep(l,x+1){
							if(dp[j][k][m][l]==0)continue;
							rep(a,10){
								rep(b,10){
									int jj = j,kk = k;
									if(a<xx)jj = 0;
									if(a>xx)jj = 1;
									if(b<xx)kk = 0;
									if(b>xx)kk = 1;
									int ll = l;
									int mm = 0;
									if(m+a+b>=10){
										ll++;
										mm = 1;
									}
									if(ll>x)continue;
									ndp[jj][kk][mm][ll] += dp[j][k][m][l];
								}
							}
						}
					}
				}
			
			}
			swap(dp,ndp);
		}
		cout<<dp[0][0][0][x].val()<<endl;
		
	}
	return 0;
}
0