結果
| 問題 |
No.2302 Carry X Times
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-12 22:31:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 1,888 bytes |
| コンパイル時間 | 1,362 ms |
| コンパイル使用メモリ | 128,736 KB |
| 最終ジャッジ日時 | 2025-02-12 23:15:54 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 24 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
const ll mod = 998244353;
ll dp[22][22][3][3][2];
void solve(){
ll N; int X; cin >> N >> X;
string S = to_string(N);
reverse(all(S));
rep(i,22) rep(j,22) rep(k,3) rep(l,3) rep(m,2) dp[i][j][k][l][m]=0;
dp[0][0][1][1][0]=1;
rep(i,sz(S)){
int n = S[i]-'0';
rep(x,X+1){
rep(aa,3){
rep(bb,3){
rep(c,2){
rep(a,10){
rep(b,10){
int s = a+b+c;
int na,nb;
if(n==a) na=aa;
else if(n>a) na=0;
else if(n<a) na=2;
if(n==b) nb=bb;
else if(n>b) nb=0;
else if(n<b) nb=2;
dp[i+1][x+(s>=10)][na][nb][s>=10]+=dp[i][x][aa][bb][c];
dp[i+1][x+(s>=10)][na][nb][s>=10]%=mod;
}
}
}
}
}
}
}
ll ans = 0;
rep(i,2) rep(j,2) rep(k,2) ans += dp[sz(S)][X][i][j][k];
cout << ans%mod << '\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T; cin >> T;
while(T--) solve();
return 0;
}