結果

問題 No.2302 Carry X Times
ユーザー 👑 NachiaNachia
提出日時 2023-05-12 21:54:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,767 bytes
コンパイル時間 999 ms
コンパイル使用メモリ 96,132 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 11:42:51
合計ジャッジ時間 2,561 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
5,248 KB
testcase_01 AC 12 ms
5,376 KB
testcase_02 AC 30 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 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 2 ms
5,376 KB
testcase_10 AC 53 ms
5,376 KB
testcase_11 AC 51 ms
5,376 KB
testcase_12 AC 55 ms
5,376 KB
testcase_13 AC 42 ms
5,376 KB
testcase_14 AC 54 ms
5,376 KB
testcase_15 AC 29 ms
5,376 KB
testcase_16 AC 27 ms
5,376 KB
testcase_17 AC 52 ms
5,376 KB
testcase_18 AC 36 ms
5,376 KB
testcase_19 AC 38 ms
5,376 KB
testcase_20 AC 39 ms
5,376 KB
testcase_21 AC 38 ms
5,376 KB
testcase_22 AC 35 ms
5,376 KB
testcase_23 AC 37 ms
5,376 KB
testcase_24 AC 35 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
#include <atcoder/modint>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;

i64 N;
map<tuple<bool, bool, i64, bool, int>, Modint> mem;

Modint dp(bool boundedA, bool boundedB, i64 dig, bool do_inc, int inccnt){
    if(inccnt < 0) return 0;
    if(dig == 0){
        if(do_inc) return 0;
        if(inccnt > 0) return 0;
        return 1;
    }
    if(mem.count({ boundedA, boundedB, dig, do_inc, inccnt })) return mem[{ boundedA, boundedB, dig, do_inc, inccnt }];
    Modint ans = 0;
    int digN = N / dig % 10;
    i64 nxdig = dig / 10;
    rep(da, 10) rep(db, 10){
        if(da > digN && !boundedA) continue;
        if(db > digN && !boundedB) continue;
        bool nxboundedA = da < digN || boundedA;
        bool nxboundedB = db < digN || boundedB;
        rep(inc, 2){
            bool real_do_inc = inc + da + db >= 10;
            if(real_do_inc && !do_inc) continue;
            if(!real_do_inc && do_inc) continue;
            ans += dp(nxboundedA, nxboundedB, nxdig, inc, inccnt - inc);
        }
    }
    return mem[{ boundedA, boundedB, dig, do_inc, inccnt }] = ans;
}

int main(){
    int T; cin >> T;
    rep(t,T){
        mem.clear();
        cin >> N;
        int X; cin >> X;
        cout << dp(false, false, 1'000'000'000'000'000'000, false, X).val() << endl;
    }
    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0