結果

問題 No.2455 Numbers Dictionary
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-08-16 18:49:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 816 bytes
コンパイル時間 1,816 ms
コンパイル使用メモリ 199,012 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-26 22:57:13
合計ジャッジ時間 3,721 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

//Kを接頭辞としてもつ数字のうち、N以下であるものの数
ll f(ll K, ll N){
    if (K > N) return 0;
    ll res = 1, Z=K;
    while(Z<=N && K<=N/10){
        Z = Z*10+9;
        K *= 10;
        res += min(Z, N)-K+1;
    }
    return res;
}

//辞書順でK以下、数字でN以下であるものの数
string K;
ll N;

ll g(ll idx=0, ll num=0){
    num *= 10;
    ll c = K[idx]-'0', res = 0;
    if (idx != 0 && c != 0) res += f(num, N);
    if (num+c <= N) res++;

    for (int i=1; i<c; i++) res += f(num+i, N);
    if (idx < K.size()-1) res += g(idx+1, num+c);

    return res;
}

int main(){

    int T;
    cin >> T;

    while(T){
        T--;
        cin >> K >> N;
        cout << g() << endl;
    }

    return 0;
}
0