結果

問題 No.658 テトラナッチ数列 Hard
ユーザー ntudantuda
提出日時 2022-10-31 20:10:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 508 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 81,088 KB
最終ジャッジ日時 2023-09-22 16:46:41
合計ジャッジ時間 3,107 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
78,204 KB
testcase_01 AC 107 ms
78,480 KB
testcase_02 AC 108 ms
78,480 KB
testcase_03 AC 109 ms
78,564 KB
testcase_04 AC 161 ms
81,068 KB
testcase_05 AC 163 ms
81,004 KB
testcase_06 AC 167 ms
81,060 KB
testcase_07 AC 164 ms
80,956 KB
testcase_08 AC 163 ms
80,984 KB
testcase_09 AC 163 ms
81,088 KB
testcase_10 AC 162 ms
81,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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])
0