結果
問題 | No.1269 I hate Fibonacci Number |
ユーザー | mkawa2 |
提出日時 | 2023-11-08 18:59:25 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 993 ms / 3,000 ms |
コード長 | 2,164 bytes |
コンパイル時間 | 267 ms |
コンパイル使用メモリ | 82,328 KB |
実行使用メモリ | 77,656 KB |
最終ジャッジ日時 | 2024-09-25 23:51:08 |
合計ジャッジ時間 | 9,808 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
55,204 KB |
testcase_01 | AC | 39 ms
54,844 KB |
testcase_02 | AC | 99 ms
76,436 KB |
testcase_03 | AC | 39 ms
55,052 KB |
testcase_04 | AC | 38 ms
54,240 KB |
testcase_05 | AC | 38 ms
54,788 KB |
testcase_06 | AC | 37 ms
55,864 KB |
testcase_07 | AC | 38 ms
55,052 KB |
testcase_08 | AC | 37 ms
55,040 KB |
testcase_09 | AC | 36 ms
55,332 KB |
testcase_10 | AC | 41 ms
54,416 KB |
testcase_11 | AC | 40 ms
54,836 KB |
testcase_12 | AC | 39 ms
55,060 KB |
testcase_13 | AC | 55 ms
67,780 KB |
testcase_14 | AC | 828 ms
77,068 KB |
testcase_15 | AC | 151 ms
76,800 KB |
testcase_16 | AC | 989 ms
77,404 KB |
testcase_17 | AC | 80 ms
76,588 KB |
testcase_18 | AC | 993 ms
77,656 KB |
testcase_19 | AC | 622 ms
76,964 KB |
testcase_20 | AC | 205 ms
76,824 KB |
testcase_21 | AC | 575 ms
77,276 KB |
testcase_22 | AC | 478 ms
76,700 KB |
testcase_23 | AC | 541 ms
76,880 KB |
testcase_24 | AC | 305 ms
76,924 KB |
testcase_25 | AC | 341 ms
77,228 KB |
testcase_26 | AC | 98 ms
77,048 KB |
testcase_27 | AC | 47 ms
63,568 KB |
testcase_28 | AC | 106 ms
76,960 KB |
testcase_29 | AC | 338 ms
76,700 KB |
testcase_30 | AC | 135 ms
76,636 KB |
testcase_31 | AC | 353 ms
76,812 KB |
testcase_32 | AC | 359 ms
77,108 KB |
testcase_33 | AC | 53 ms
67,064 KB |
testcase_34 | AC | 47 ms
63,908 KB |
testcase_35 | AC | 114 ms
76,428 KB |
testcase_36 | AC | 38 ms
55,892 KB |
testcase_37 | AC | 37 ms
55,160 KB |
testcase_38 | AC | 41 ms
61,152 KB |
ソースコード
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)