結果
| 問題 |
No.1953 8
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-20 22:33:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 69 ms / 2,000 ms |
| コード長 | 1,590 bytes |
| コンパイル時間 | 137 ms |
| コンパイル使用メモリ | 81,780 KB |
| 実行使用メモリ | 72,960 KB |
| 最終ジャッジ日時 | 2024-09-20 08:49:48 |
| 合計ジャッジ時間 | 5,478 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
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)