結果

問題 No.2302 Carry X Times
ユーザー pockynypockyny
提出日時 2023-05-13 11:23:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,020 bytes
コンパイル時間 795 ms
コンパイル使用メモリ 84,040 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 12:22:21
合計ジャッジ時間 3,307 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,bool> plb;
map<pair<pll,plb>,ll> mp;
ll mod = 998244353;
ll solve(ll a,ll b,ll c,bool f){
    //cout << a << " "  << b << " "<< c << " " << f << endl;
    if(a==0 && b==0){
        if(!c) return 1;
        else return 0;
    }
    if(a<0 || b<0) return 0;
    if(mp.find({{a,b},{c,f}})!=mp.end()) return mp[{{a,b},{c,f}}];
    ll ans = 0; ll car = f;
    for(ll i=0;i<=9;i++){
        for(ll j=0;j<=9;j++){
            ll nxa = a/10 - (i>a%10);
            ll nxb = b/10 - (j>b%10);
            ll nxc = (i + j + car>=10) ? c - 1 : c;
            bool nxf = i + j + car>=10;
            (ans += solve(nxa,nxb,nxc,nxf)) %= mod;
        }
    }
    return mp[{{a,b},{c,f}}] = ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t; cin >> t;
    while(t){
        t--;
        mp.clear();
        ll n,x; cin >> n >> x;
        cout << solve(n,n,x,false) << "\n";
    }
}
0