結果
問題 | No.1269 I hate Fibonacci Number |
ユーザー |
![]() |
提出日時 | 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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
import sys# sys.setrecursionlimit(1000005)# sys.set_int_max_str_digits(200005)int1 = lambda x: int(x)-1pDB = 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 = 998244353from collections import dequedef add(s):u = 0for i, c in enumerate(s):c = int(c)if -1 in trie[u]: return uif c not in trie[u]:trie[u][c] = len(trie)trie.append({})u = trie[u][c]trie[u][-1] = sreturn un, l, r = LI()trie = [{}]def ok(s):for t in ng:if t in s: return Falsereturn Truex = y = 1ng = set()while y <= r:s = str(y)if y >= l and ok(s):add(s)ng.add(s)x, y = y, x+ydef 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 0m = len(trie)back = [0]*mq = 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] = 0else:v = back[p]back[u] = move(v, c)for c, v in trie[u].items():if c == -1: continueq.append((v, u, c, d+1))dp = [0]*mdp[0] = 1for _ in range(n):pre, dp = dp, [0]*mfor u in range(m):if pre[u] == 0: continuefor c in range(10):if c in trie[u]:v = trie[u][c]else:v = move(back[u], c)if -1 in trie[v]: continuedp[v] += pre[u]dp[v] %= mdans = -1for d in dp:ans += dans %= mdprint(ans)