結果

問題 No.1953 8
ユーザー terasaterasa
提出日時 2022-05-22 17:43:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 1,133 bytes
コンパイル時間 1,755 ms
コンパイル使用メモリ 81,624 KB
実行使用メモリ 78,952 KB
最終ジャッジ日時 2023-10-20 17:10:38
合計ジャッジ時間 8,020 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
78,348 KB
testcase_01 AC 119 ms
78,376 KB
testcase_02 AC 127 ms
78,364 KB
testcase_03 AC 110 ms
78,248 KB
testcase_04 AC 108 ms
78,256 KB
testcase_05 AC 108 ms
78,252 KB
testcase_06 AC 110 ms
78,308 KB
testcase_07 AC 106 ms
78,248 KB
testcase_08 AC 111 ms
78,316 KB
testcase_09 AC 107 ms
78,252 KB
testcase_10 AC 114 ms
78,324 KB
testcase_11 AC 117 ms
78,348 KB
testcase_12 AC 117 ms
78,376 KB
testcase_13 AC 120 ms
78,372 KB
testcase_14 AC 126 ms
78,940 KB
testcase_15 AC 125 ms
78,948 KB
testcase_16 AC 124 ms
78,936 KB
testcase_17 AC 122 ms
78,388 KB
testcase_18 AC 121 ms
78,400 KB
testcase_19 AC 123 ms
78,388 KB
testcase_20 AC 123 ms
78,364 KB
testcase_21 AC 122 ms
78,348 KB
testcase_22 AC 122 ms
78,348 KB
testcase_23 AC 122 ms
78,348 KB
testcase_24 AC 121 ms
78,348 KB
testcase_25 AC 124 ms
78,380 KB
testcase_26 AC 122 ms
78,364 KB
testcase_27 AC 123 ms
78,364 KB
testcase_28 AC 124 ms
78,952 KB
testcase_29 AC 125 ms
78,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict, Counter
import string
import random

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


K = int(input())
circle = [1, 0, 0, 0, 1, 0, 1, 0, 2, 1]

l = -1
r = 10 ** 18
while r - l > 1:
    c = (l + r) // 2

    A = [int(c) for c in str(c)]
    dp = [[[0, 0] for _ in range(50)] for _ in range(len(A) + 1)]
    dp[0][0][0] = 1
    for i in range((len(A))):
        for j in range(40):
            for k in range(10):
                n = circle[k]
                dp[i + 1][j + n][1] += dp[i][j][1]

                if k < A[i]:
                    dp[i + 1][j + n][1] += dp[i][j][0]
                elif k == A[i]:
                    dp[i + 1][j + n][0] += dp[i][j][0]
    acc = 0
    for j in range(40):
        acc += j * sum(dp[len(A)][j])

    acc -= len(A)
    for i in range(1, len(A)):
        acc -= (len(A) - i) * (pow(10, i) - pow(10, i - 1))

    if acc == K:
        print(c)
        exit()
    elif acc > K:
        r = c
    else:
        l = c
print(-1)
0