結果

問題 No.2455 Numbers Dictionary
ユーザー sotanishysotanishy
提出日時 2023-09-01 23:42:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 710 ms / 2,000 ms
コード長 863 bytes
コンパイル時間 1,091 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 80,068 KB
最終ジャッジ日時 2023-09-01 23:43:10
合計ジャッジ時間 9,090 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
75,428 KB
testcase_01 AC 69 ms
71,412 KB
testcase_02 AC 184 ms
78,328 KB
testcase_03 AC 252 ms
78,932 KB
testcase_04 AC 323 ms
79,396 KB
testcase_05 AC 201 ms
78,520 KB
testcase_06 AC 450 ms
79,748 KB
testcase_07 AC 710 ms
79,912 KB
testcase_08 AC 257 ms
79,984 KB
testcase_09 AC 431 ms
79,844 KB
testcase_10 AC 357 ms
79,008 KB
testcase_11 AC 433 ms
79,388 KB
testcase_12 AC 245 ms
78,608 KB
testcase_13 AC 444 ms
79,692 KB
testcase_14 AC 353 ms
79,400 KB
testcase_15 AC 360 ms
78,988 KB
testcase_16 AC 172 ms
78,924 KB
testcase_17 AC 571 ms
80,068 KB
testcase_18 AC 165 ms
78,768 KB
testcase_19 AC 182 ms
79,340 KB
testcase_20 AC 438 ms
79,236 KB
testcase_21 AC 468 ms
79,608 KB
testcase_22 AC 308 ms
79,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline


def calc(digits, N):
    if digits < N[:len(digits)]:
        cnt = 0
        for d in range(len(N)-len(digits)+1):
            cnt += 10**d
        return cnt
    if digits > N[:len(digits)]:
        cnt = 0
        for d in range(len(N)-len(digits)):
            cnt += 10**d
        return cnt

    res = 0
    cnt = 1
    for d in range(len(digits), len(N)):
        res = res * 10 + N[d]
    cnt += res
    for d in range(len(N)-len(digits)):
        cnt += 10**d
    return cnt


T = int(input())
for _ in range(T):
    N, K = map(int, input().split())
    N = list(map(int, str(N)))
    K = list(map(int, str(K)))
    ans = 0

    for i, x in enumerate(K):
        for y in range(x):
            if i == 0 and y == 0:
                continue
            ans += calc(K[:i] + [y], N)
        ans += 1

    print(ans)
0