結果

問題 No.362 門松ナンバー
ユーザー maspymaspy
提出日時 2020-03-12 23:10:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,968 ms / 3,000 ms
コード長 1,151 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 10,824 KB
実行使用メモリ 80,136 KB
最終ジャッジ日時 2023-08-12 17:57:37
合計ジャッジ時間 20,577 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
9,208 KB
testcase_01 AC 42 ms
9,396 KB
testcase_02 AC 29 ms
9,080 KB
testcase_03 AC 37 ms
9,420 KB
testcase_04 AC 37 ms
9,104 KB
testcase_05 AC 186 ms
16,128 KB
testcase_06 AC 525 ms
26,416 KB
testcase_07 AC 446 ms
25,840 KB
testcase_08 AC 714 ms
31,948 KB
testcase_09 AC 1,274 ms
51,776 KB
testcase_10 AC 1,968 ms
80,136 KB
testcase_11 AC 1,858 ms
79,708 KB
testcase_12 AC 1,914 ms
79,880 KB
testcase_13 AC 1,948 ms
79,632 KB
testcase_14 AC 1,876 ms
79,660 KB
testcase_15 AC 1,941 ms
79,528 KB
testcase_16 AC 999 ms
44,376 KB
testcase_17 AC 749 ms
32,248 KB
testcase_18 AC 1,061 ms
45,212 KB
testcase_19 AC 32 ms
9,412 KB
testcase_20 AC 1,052 ms
45,000 KB
testcase_21 AC 199 ms
14,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import lru_cache


# %%
def is_kadomatsu(a, b, c):
    if a == c:
        return False
    return (a < b > c) or (a > b < c)


# %%
@lru_cache(None)
def count_kadomatsu(N, x):
    """counting kadomatsu number K such that:
    1 <= K <= N and K = x mod 100"""
    if N < 100:
        return 0
    ret = 0
    q, r = divmod(x, 10)
    for i in range(10):
        if 100 * i + x <= N and is_kadomatsu(i, q, r):
            if i:
                ret += 1
            ret += count_kadomatsu((N - r) // 10, 10 * i + q)
    return ret


def count_kadomatsu_all(N):
    return sum(count_kadomatsu(N, x) for x in range(100))


# %%
def solve(K):
    left = 0
    right = K
    while count_kadomatsu_all(right) < K:
        right *= 10
    while left + 1 < right:
        mid = (left + right) // 2
        if count_kadomatsu_all(mid) >= K:
            right = mid
        else:
            left = mid
    return right


# %%
T, *K = map(int, read().split())
print('\n'.join(map(str, map(solve, K))))
0