結果
問題 | No.1269 I hate Fibonacci Number |
ユーザー | tpyneriver |
提出日時 | 2021-01-11 12:54:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 197 ms / 3,000 ms |
コード長 | 3,417 bytes |
コンパイル時間 | 152 ms |
コンパイル使用メモリ | 82,460 KB |
実行使用メモリ | 76,888 KB |
最終ジャッジ日時 | 2024-05-01 06:46:47 |
合計ジャッジ時間 | 4,824 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
54,708 KB |
testcase_01 | AC | 41 ms
55,072 KB |
testcase_02 | AC | 63 ms
68,876 KB |
testcase_03 | AC | 41 ms
55,400 KB |
testcase_04 | AC | 42 ms
56,324 KB |
testcase_05 | AC | 42 ms
55,648 KB |
testcase_06 | AC | 42 ms
54,972 KB |
testcase_07 | AC | 42 ms
54,480 KB |
testcase_08 | AC | 42 ms
55,532 KB |
testcase_09 | AC | 46 ms
55,260 KB |
testcase_10 | AC | 43 ms
54,976 KB |
testcase_11 | AC | 42 ms
56,480 KB |
testcase_12 | AC | 41 ms
55,116 KB |
testcase_13 | AC | 77 ms
76,784 KB |
testcase_14 | AC | 164 ms
76,652 KB |
testcase_15 | AC | 77 ms
72,816 KB |
testcase_16 | AC | 156 ms
76,872 KB |
testcase_17 | AC | 57 ms
65,020 KB |
testcase_18 | AC | 162 ms
76,384 KB |
testcase_19 | AC | 197 ms
76,596 KB |
testcase_20 | AC | 95 ms
76,640 KB |
testcase_21 | AC | 121 ms
76,800 KB |
testcase_22 | AC | 165 ms
76,800 KB |
testcase_23 | AC | 165 ms
76,584 KB |
testcase_24 | AC | 92 ms
76,588 KB |
testcase_25 | AC | 127 ms
76,500 KB |
testcase_26 | AC | 58 ms
67,232 KB |
testcase_27 | AC | 48 ms
63,212 KB |
testcase_28 | AC | 65 ms
71,916 KB |
testcase_29 | AC | 123 ms
76,420 KB |
testcase_30 | AC | 80 ms
73,136 KB |
testcase_31 | AC | 153 ms
76,804 KB |
testcase_32 | AC | 100 ms
76,888 KB |
testcase_33 | AC | 98 ms
76,772 KB |
testcase_34 | AC | 48 ms
64,316 KB |
testcase_35 | AC | 72 ms
71,212 KB |
testcase_36 | AC | 54 ms
65,072 KB |
testcase_37 | AC | 42 ms
56,132 KB |
testcase_38 | AC | 55 ms
64,840 KB |
ソースコード
import sys readline = sys.stdin.readline from collections import deque class AhoCorasick: def __init__(self, patterns): self.patterns = patterns self.children = [dict()] self.N = 1 self.match = [False] self.order = [0] """ 例えばで、 self.match に patterns のうちどれかが部分文字列になっているかどうかを格納 禁止文字列とかの場合 self.match が True だと使えない """ for i in range(len(patterns)): self._add(i, patterns[i]) self.failure = [0]*self.N self._createfailure() def _add(self, i, p): vn = 0 for pi in p: if pi in self.children[vn]: vn = self.children[vn][pi] else: self.children[vn][pi] = self.N self.children.append(dict()) self.match.append(False) vn = self.N self.N += 1 self.match[vn] = True def _createfailure(self): Q = deque(self.children[0].values()) while Q: vn = Q.pop() self.order.append(vn) fvn = self.failure[vn] self.match[vn] |= self.match[fvn] for fpi, vf in self.children[vn].items(): self.failure[vf] = self.nxt(fvn, fpi) self.match[vf] |= self.match[vn] Q.appendleft(vf) def nxt(self, vn, s): #vnにsを付け足した時の遷移先 while True: if s in self.children[vn]: return self.children[vn][s] if not vn: return vn vn = self.failure[vn] def idx(self, p): #文字列pのindexを返す vn = 0 for pi in p: if pi in self.children[vn]: vn = self.children[vn][pi] else: return -1 return vn def getnxttable(self, sigma): #[0, sigma) に対して各ノードからの遷移先を求める #res[s*self.N + vn] = nxt(vn, s) res = [0]*(self.N*sigma) for l in self.order: for s in range(sigma): if s in self.children[l]: res[s*self.N + l] = self.children[l][s] else: res[s*self.N + l] = res[s*self.N + self.failure[l]] return res def __repr__(self): SS = [None]*self.N SS[0] = '' Q = deque([0]) while Q: vn = Q.pop() for c, vf in self.children[vn].items(): SS[vf] = f'{SS[vn]} {c}' Q.appendleft(vf) return '\n'.join(f'{i}:{SS[i]} {self.match[i]}' for i in range(self.N)) N, L, R = map(int, readline().split()) MOD = 10**9+7 Fib = [] a, b = 1, 1 while b <= R: Fib.append(b) a, b = b, a+b L -= 1 a, b = 1, 1 while b <= L: Fib.remove(b) a, b = b, a+b Fib = [tuple(map(int, str(s))) for s in Fib] ahc = AhoCorasick(Fib) M = ahc.N table = ahc.getnxttable(10) dp = [0]*M dp[0] = 1 for _ in range(N): dp2 = [0]*M for i in range(M): if not dp[i]: continue for s in range(10): vf = table[s*M + i] if not ahc.match[vf]: dp2[vf] = (dp2[vf] + dp[i])%MOD dp = dp2[:] ans = MOD-1 for d in dp: ans = (ans + d)%MOD print(ans)