結果
問題 |
No.1953 8
|
ユーザー |
![]() |
提出日時 | 2022-05-26 18:19:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 64 ms / 2,000 ms |
コード長 | 1,301 bytes |
コンパイル時間 | 182 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 66,688 KB |
最終ジャッジ日時 | 2024-09-20 15:04:24 |
合計ジャッジ時間 | 5,398 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#!/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)