結果
問題 | No.658 テトラナッチ数列 Hard |
ユーザー |
![]() |
提出日時 | 2022-10-31 20:10:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 108 ms / 2,000 ms |
コード長 | 508 bytes |
コンパイル時間 | 150 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 78,848 KB |
最終ジャッジ日時 | 2024-07-08 08:14:12 |
合計ジャッジ時間 | 1,990 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 |
ソースコード
from collections import defaultdict Q = int(input()) N = 10 ** 5 T = [0] * (N + 1) T[4] = 1 dic = defaultdict(int) tmp = sum(T[1:5]) for i in range(5, N + 1): T[i] = tmp if tuple(T[i - 4:i]) not in dic: dic[tuple(T[i - 4:i])] = i else: start = dic[tuple(T[i - 4:i])] seq = i - start break tmp += T[i] - T[i - 4] tmp %= 17 for _ in range(Q): n = int(input()) if n <= start: print(T[n]) else: print(T[start + (n - start) % seq])