結果

問題 No.1953 8
ユーザー chineristACchineristAC
提出日時 2022-05-20 22:33:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,590 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 81,624 KB
実行使用メモリ 72,896 KB
最終ジャッジ日時 2023-10-20 13:18:57
合計ジャッジ時間 6,124 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
70,832 KB
testcase_01 AC 71 ms
72,880 KB
testcase_02 AC 79 ms
72,896 KB
testcase_03 AC 73 ms
70,832 KB
testcase_04 AC 72 ms
70,832 KB
testcase_05 AC 71 ms
70,832 KB
testcase_06 AC 71 ms
70,832 KB
testcase_07 AC 72 ms
70,832 KB
testcase_08 AC 71 ms
70,832 KB
testcase_09 AC 71 ms
70,832 KB
testcase_10 AC 72 ms
70,832 KB
testcase_11 AC 71 ms
70,832 KB
testcase_12 AC 74 ms
72,880 KB
testcase_13 AC 72 ms
72,876 KB
testcase_14 AC 73 ms
72,884 KB
testcase_15 AC 73 ms
72,884 KB
testcase_16 AC 74 ms
72,892 KB
testcase_17 AC 73 ms
72,812 KB
testcase_18 AC 73 ms
72,824 KB
testcase_19 AC 74 ms
72,828 KB
testcase_20 AC 73 ms
72,888 KB
testcase_21 AC 72 ms
72,880 KB
testcase_22 AC 70 ms
70,812 KB
testcase_23 AC 73 ms
72,888 KB
testcase_24 AC 71 ms
70,812 KB
testcase_25 AC 70 ms
70,808 KB
testcase_26 AC 74 ms
72,896 KB
testcase_27 AC 76 ms
72,896 KB
testcase_28 AC 72 ms
72,884 KB
testcase_29 AC 71 ms
72,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
import heapq
from itertools import permutations
from math import gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

memo = {}
def calc(n):
    if n in memo:
        return memo[n]
    if n<=0:
        return 0

    """
    1~nまででの丸の数
    1個:4,6,9,0
    2個:8
    """

    res = 0

    for i in (1,2,3,5,7):
        if i <= n%10:
            res += calc(n//10)
        else:
            res += calc(n//10-1)


    for i in (0,4,6,9):
        if i==0:
            res += n//10
        else:
            if i <= n%10:
                res += n//10 + 1
            else:
                res += n//10
        
        if i <= n%10:
            res += calc(n//10)
        else:
            res += calc(n//10-1)
    
    for i in (8,):
        if i <= n%10:
            res += (n//10 + 1) * 2
        else:
            res += (n//10) * 2
        if i <= n%10:
            res += calc(n//10)
        else:
            res += calc(n//10-1)
    
    memo[n] = res
    return res

def calc_brute(n):
    res = [0] * (n+1)
    for i in range(1,n+1):
        s = str(i)
        res[i] = res[i-1]
        for j in ("0","4","6","9"):
            res[i] += s.count(j)
        for j in ("8"):
            res[i] += s.count(j) * 2
    return res



K = int(input())

ok = 10**18
ng = 0
while ok-ng>1:
    mid = (ok+ng)//2
    if calc(mid) >= K:
        ok = mid
    else:
        ng = mid

if calc(ok)==K:
    print(ok)
else:
    print(-1)

            
    
0