結果

問題 No.1953 8
ユーザー siganaisiganai
提出日時 2022-05-26 18:19:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,301 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 81,460 KB
実行使用メモリ 67,580 KB
最終ジャッジ日時 2023-10-20 19:31:10
合計ジャッジ時間 5,687 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
65,460 KB
testcase_01 AC 57 ms
65,532 KB
testcase_02 AC 62 ms
65,532 KB
testcase_03 AC 56 ms
65,532 KB
testcase_04 AC 55 ms
65,532 KB
testcase_05 AC 62 ms
65,532 KB
testcase_06 AC 56 ms
65,532 KB
testcase_07 AC 55 ms
65,532 KB
testcase_08 AC 56 ms
65,532 KB
testcase_09 AC 55 ms
65,532 KB
testcase_10 AC 56 ms
65,532 KB
testcase_11 AC 54 ms
65,532 KB
testcase_12 AC 55 ms
65,532 KB
testcase_13 AC 56 ms
65,532 KB
testcase_14 AC 55 ms
65,532 KB
testcase_15 AC 56 ms
65,532 KB
testcase_16 AC 56 ms
65,532 KB
testcase_17 AC 55 ms
65,532 KB
testcase_18 AC 58 ms
65,532 KB
testcase_19 AC 57 ms
65,532 KB
testcase_20 AC 59 ms
65,532 KB
testcase_21 AC 58 ms
65,532 KB
testcase_22 AC 59 ms
65,532 KB
testcase_23 AC 59 ms
65,532 KB
testcase_24 AC 60 ms
67,580 KB
testcase_25 AC 60 ms
67,580 KB
testcase_26 AC 59 ms
65,532 KB
testcase_27 AC 57 ms
67,580 KB
testcase_28 AC 57 ms
65,532 KB
testcase_29 AC 55 ms
65,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env PyPy3

from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
from heapq import *
import functools

mod=998244353

import sys
input = sys.stdin.readline

li = [1,1,1,1,2,2,3,3,5,6]
def is_ok(x):
    strx = str(x)
    dp = [[0] * len(strx) for _ in range(2)]
    cnt = [[0] * len(strx) for _ in range(2)]
    dp[0][0] = li[int(strx[0]) - 1] - 1
    dp[1][0] = li[int(strx[0])] - li[int(strx[0]) - 1]
    cnt[0][0] = int(strx[0]) - 1
    cnt[1][0] = 1
    for i in range(1,len(strx)):
        dp[0][i] += 5
        dp[0][i] += dp[0][i-1] * 10 + 6 * cnt[0][i-1]
        if int(strx[i]) - 1 >= 0:
            dp[0][i] += dp[1][i-1] * int(strx[i]) + li[int(strx[i]) - 1]
        if int(strx[i]) - 1 >= 0:
            dp[1][i] = dp[1][i-1] + li[int(strx[i])] - li[int(strx[i]) - 1]
        else:
            dp[1][i] = dp[1][i-1] + 1
        cnt[1][i] = 1
        cnt[0][i] = cnt[0][i-1] * 10 + 9 + int(strx[i])
    return dp[0][-1] + dp[1][-1] >= k,dp[0][-1] + dp[1][-1]
k = int(input())
ok = 10 ** 18
ng = 0
while ok - ng > 1:
    mid = (ng + ok) // 2
    flg,_ = is_ok(mid)
    if flg:
        ok = mid
    else:
        ng = mid
_,ans = is_ok(ok)
if ans == k:
    print(ok)
else:
    print(-1)
0