結果

問題 No.294 SuperFizzBuzz
ユーザー yuppe19 😺yuppe19 😺
提出日時 2018-11-11 17:34:49
言語 Python2
(2.7.18)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 1,294 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 6,636 KB
実行使用メモリ 6,008 KB
最終ジャッジ日時 2023-08-20 18:44:28
合計ジャッジ時間 1,985 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
5,984 KB
testcase_01 AC 36 ms
5,832 KB
testcase_02 AC 51 ms
5,908 KB
testcase_03 AC 35 ms
5,812 KB
testcase_04 AC 34 ms
5,996 KB
testcase_05 AC 34 ms
5,904 KB
testcase_06 AC 37 ms
5,972 KB
testcase_07 AC 39 ms
5,956 KB
testcase_08 AC 45 ms
5,892 KB
testcase_09 AC 50 ms
5,860 KB
testcase_10 AC 50 ms
6,008 KB
testcase_11 AC 50 ms
5,900 KB
testcase_12 AC 51 ms
5,828 KB
testcase_13 AC 50 ms
5,964 KB
testcase_14 AC 51 ms
5,900 KB
権限があれば一括ダウンロードができます

ソースコード

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