結果
| 問題 |
No.2455 Numbers Dictionary
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-01 21:54:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 308 ms / 2,000 ms |
| コード長 | 973 bytes |
| コンパイル時間 | 352 ms |
| コンパイル使用メモリ | 82,148 KB |
| 実行使用メモリ | 78,648 KB |
| 最終ジャッジ日時 | 2025-01-03 08:22:31 |
| 合計ジャッジ時間 | 5,730 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 22 |
ソースコード
import sys,random
from itertools import permutations
from collections import deque
input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())
def calc(prefix,upper):
ans = 0
n = len(prefix)
m = len(upper)
if n > m:
return 0
ans += (10**(m-n)-1)//9
k = m-n
a = int(prefix)
b = int(upper[:len(prefix)])
if a == b:
ans += int(upper[len(prefix):]) + 1
elif a < b:
ans += 10**k
return ans
def solve(N,K):
ans = 0
for i in range(len(K)):
t = K[:i+1]
for j in range(1,int(t[-1])+1):
prefix = str(int(t)-j)
if prefix == "0":
continue
ans += calc(prefix,N)
ans += len(K)
return ans
def brute(N,K):
tmp = [str(i) for i in range(1,int(N)+1)]
tmp.sort()
return tmp.index(K) + 1
for _ in range(int(input())):
N,K = input().split()
print(solve(N,K))