結果

問題 No.1269 I hate Fibonacci Number
ユーザー mkawa2mkawa2
提出日時 2023-11-08 18:59:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,207 ms / 3,000 ms
コード長 2,164 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,120 KB
最終ジャッジ日時 2023-11-08 18:59:41
合計ジャッジ時間 11,794 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,600 KB
testcase_01 AC 41 ms
55,600 KB
testcase_02 AC 109 ms
76,220 KB
testcase_03 AC 41 ms
55,600 KB
testcase_04 AC 42 ms
55,600 KB
testcase_05 AC 42 ms
55,600 KB
testcase_06 AC 43 ms
55,600 KB
testcase_07 AC 42 ms
55,600 KB
testcase_08 AC 43 ms
55,600 KB
testcase_09 AC 42 ms
55,600 KB
testcase_10 AC 42 ms
55,600 KB
testcase_11 AC 42 ms
55,600 KB
testcase_12 AC 46 ms
55,600 KB
testcase_13 AC 58 ms
66,528 KB
testcase_14 AC 915 ms
76,600 KB
testcase_15 AC 166 ms
76,212 KB
testcase_16 AC 1,101 ms
77,120 KB
testcase_17 AC 92 ms
76,072 KB
testcase_18 AC 1,207 ms
76,992 KB
testcase_19 AC 751 ms
76,480 KB
testcase_20 AC 242 ms
76,336 KB
testcase_21 AC 657 ms
76,728 KB
testcase_22 AC 563 ms
76,472 KB
testcase_23 AC 639 ms
76,344 KB
testcase_24 AC 351 ms
76,468 KB
testcase_25 AC 427 ms
76,340 KB
testcase_26 AC 103 ms
76,224 KB
testcase_27 AC 51 ms
64,304 KB
testcase_28 AC 114 ms
76,492 KB
testcase_29 AC 370 ms
76,204 KB
testcase_30 AC 152 ms
76,216 KB
testcase_31 AC 442 ms
76,320 KB
testcase_32 AC 426 ms
76,476 KB
testcase_33 AC 58 ms
66,528 KB
testcase_34 AC 50 ms
64,304 KB
testcase_35 AC 126 ms
76,208 KB
testcase_36 AC 42 ms
55,600 KB
testcase_37 AC 42 ms
55,600 KB
testcase_38 AC 74 ms
61,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 63)
md = 10**9+7
# md = 998244353

from collections import deque

def add(s):
    u = 0
    for i, c in enumerate(s):
        c = int(c)
        if -1 in trie[u]: return u
        if c not in trie[u]:
            trie[u][c] = len(trie)
            trie.append({})
        u = trie[u][c]
    trie[u][-1] = s
    return u

n, l, r = LI()

trie = [{}]

def ok(s):
    for t in ng:
        if t in s: return False
    return True

x = y = 1
ng = set()
while y <= r:
    s = str(y)
    if y >= l and ok(s):
        add(s)
        ng.add(s)
    x, y = y, x+y

def move(v, c):
    while v and c not in trie[v]:
        v = back[v]
        # print(v)
    if c in trie[v]: return trie[v][c]
    return 0

m = len(trie)
back = [0]*m
q = deque()
for c, v in trie[0].items(): q.append((v, 0, c, 1))

while q:
    u, p, c, d = q.popleft()
    if d == 1:
        back[u] = 0
    else:
        v = back[p]
        back[u] = move(v, c)
    for c, v in trie[u].items():
        if c == -1: continue
        q.append((v, u, c, d+1))

dp = [0]*m
dp[0] = 1
for _ in range(n):
    pre, dp = dp, [0]*m
    for u in range(m):
        if pre[u] == 0: continue
        for c in range(10):
            if c in trie[u]:
                v = trie[u][c]
            else:
                v = move(back[u], c)
            if -1 in trie[v]: continue
            dp[v] += pre[u]
            dp[v] %= md

ans = -1
for d in dp:
    ans += d
    ans %= md

print(ans)
0