結果
問題 | No.657 テトラナッチ数列 Easy |
ユーザー | Theta |
提出日時 | 2022-10-18 18:10:58 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,917 bytes |
コンパイル時間 | 631 ms |
コンパイル使用メモリ | 10,800 KB |
実行使用メモリ | 174,892 KB |
最終ジャッジ日時 | 2023-09-11 10:49:47 |
合計ジャッジ時間 | 13,697 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
8,072 KB |
testcase_01 | AC | 17 ms
8,140 KB |
testcase_02 | AC | 17 ms
8,196 KB |
testcase_03 | AC | 17 ms
7,988 KB |
testcase_04 | TLE | - |
testcase_05 | AC | 62 ms
8,068 KB |
testcase_06 | AC | 17 ms
8,064 KB |
testcase_07 | AC | 16 ms
8,052 KB |
testcase_08 | TLE | - |
testcase_09 | AC | 67 ms
8,552 KB |
testcase_10 | AC | 88 ms
9,936 KB |
testcase_11 | AC | 87 ms
9,920 KB |
testcase_12 | AC | 273 ms
26,964 KB |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
ソースコード
class Modint: MOD = 17 def __init__(self, value: int) -> None: self.num = value % Modint.MOD def __str__(self) -> str: return str(self.num) __repr__ = __str__ def __add__(self, __x): if isinstance(__x, Modint): return Modint((self.num + __x.num)) return Modint(self.num + __x) def __sub__(self, __x): if isinstance(__x, Modint): return Modint(self.num - __x.num) return Modint(self.num - __x) def __mul__(self, __x): if isinstance(__x, Modint): return Modint(self.num * __x.num) return Modint(self.num * __x) __radd__ = __add__ __rmul__ = __mul__ def __rsub__(self, __x): if isinstance(__x, Modint): return Modint(__x.num - self.num) return Modint(__x - self.num) def __pow__(self, __x): if isinstance(__x, Modint): return Modint(pow(self.num, __x.num, Modint.MOD)) return Modint(pow(self.num, __x, Modint.MOD)) def __rpow__(self, __x): if isinstance(__x, Modint): return Modint(pow(__x.num, self.num, Modint.MOD)) return Modint(pow(__x, self.num, Modint.MOD)) class Tetranacci: def __init__(self): self._array = {1: Modint(0), 2: Modint(0), 3: Modint(0), 4: Modint(1)} self.max_idx = 4 def calc(self, idx: int) -> int: if idx <= self.max_idx: return self._array[idx] for _idx in range(self.max_idx+1, idx+1): self._array[_idx] = ( self._array[_idx-4] + self._array[_idx-3] + self._array[_idx-2] + self._array[_idx-1] ) self.max_idx = max(self.max_idx, idx) return self._array[idx] def main(): Q = int(input()) array = Tetranacci() for _ in range(Q): print(array.calc(int(input()))) if __name__ == "__main__": main()