結果
問題 | No.1269 I hate Fibonacci Number |
ユーザー | tpyneriver |
提出日時 | 2021-01-11 12:54:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 201 ms / 3,000 ms |
コード長 | 3,417 bytes |
コンパイル時間 | 310 ms |
コンパイル使用メモリ | 82,368 KB |
実行使用メモリ | 76,928 KB |
最終ジャッジ日時 | 2024-11-21 09:01:12 |
合計ジャッジ時間 | 4,903 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
55,568 KB |
testcase_01 | AC | 46 ms
54,832 KB |
testcase_02 | AC | 69 ms
69,424 KB |
testcase_03 | AC | 44 ms
55,116 KB |
testcase_04 | AC | 45 ms
55,484 KB |
testcase_05 | AC | 45 ms
55,164 KB |
testcase_06 | AC | 44 ms
55,120 KB |
testcase_07 | AC | 45 ms
55,792 KB |
testcase_08 | AC | 45 ms
55,248 KB |
testcase_09 | AC | 48 ms
54,420 KB |
testcase_10 | AC | 44 ms
55,128 KB |
testcase_11 | AC | 45 ms
55,060 KB |
testcase_12 | AC | 45 ms
55,380 KB |
testcase_13 | AC | 80 ms
76,832 KB |
testcase_14 | AC | 170 ms
76,928 KB |
testcase_15 | AC | 81 ms
74,180 KB |
testcase_16 | AC | 162 ms
76,376 KB |
testcase_17 | AC | 57 ms
66,252 KB |
testcase_18 | AC | 168 ms
76,724 KB |
testcase_19 | AC | 201 ms
76,516 KB |
testcase_20 | AC | 102 ms
76,384 KB |
testcase_21 | AC | 124 ms
76,620 KB |
testcase_22 | AC | 169 ms
76,728 KB |
testcase_23 | AC | 171 ms
76,288 KB |
testcase_24 | AC | 97 ms
76,668 KB |
testcase_25 | AC | 131 ms
76,720 KB |
testcase_26 | AC | 62 ms
68,596 KB |
testcase_27 | AC | 52 ms
62,600 KB |
testcase_28 | AC | 71 ms
71,844 KB |
testcase_29 | AC | 127 ms
76,268 KB |
testcase_30 | AC | 78 ms
72,436 KB |
testcase_31 | AC | 156 ms
76,744 KB |
testcase_32 | AC | 103 ms
76,740 KB |
testcase_33 | AC | 104 ms
76,580 KB |
testcase_34 | AC | 53 ms
63,832 KB |
testcase_35 | AC | 72 ms
70,644 KB |
testcase_36 | AC | 58 ms
65,804 KB |
testcase_37 | AC | 46 ms
56,352 KB |
testcase_38 | AC | 58 ms
65,328 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)