結果

問題 No.294 SuperFizzBuzz
ユーザー yuppe19 😺
提出日時 2018-11-11 17:34:49
言語 Python2
(2.7.18)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 1,294 bytes
コンパイル時間 663 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-11-30 22:41:04
合計ジャッジ時間 1,590 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python2
# -*- coding: utf-8 -*-
# †
def f(x):
    a = map(int, str(x))
    n = len(a)
    # dp[][nuke0][15でのあまり] := パターン数
    dp = [[[0] * 15 for _ in xrange(2)] for _ in xrange(2)]
    dp[0][0][0] = 1
    for i in xrange(n):
        ndp = [[[0] * 15 for _ in xrange(2)] for _ in xrange(2)]
        for less in xrange(2):
            for nuke0 in xrange(2):
                for rem in xrange(15):
                    if dp[less][nuke0][rem] == 0:
                        continue
                    for d in xrange(10 if less else a[i]+1):
                        if d != 0 and d != 3 and d != 5:
                            continue
                        if nuke0 and d == 0:
                            continue
                        nless = less or d < a[i]
                        n_nuke0 = nuke0 or d > 0
                        nrem  = (rem * 10 + d) % 15
                        ndp[nless][n_nuke0][nrem] += dp[less][nuke0][rem]
        dp = ndp
    res = 0
    for less in xrange(2):
        res += dp[less][1][0]
    return res


def g(n):
    lo, hi = 0, 2**100
    while hi - lo > 1:
        md = (lo + hi) / 2
        if f(md) < n:
            lo = md
        else:
            hi = md
    return hi


n = int(raw_input())
res = g(n)
print res
0