結果
問題 |
No.1097 Remainder Operation
|
ユーザー |
![]() |
提出日時 | 2020-06-26 22:33:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 458 bytes |
コンパイル時間 | 155 ms |
コンパイル使用メモリ | 82,156 KB |
実行使用メモリ | 89,032 KB |
最終ジャッジ日時 | 2024-07-04 22:18:26 |
合計ジャッジ時間 | 3,517 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 1 |
other | AC * 2 WA * 4 RE * 15 |
ソースコード
import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) Q = int(input()) Query = [int(input()) for _ in range(Q)] D = [-1]*N P = [] x = 0 j = 0 while D[x%N] == -1: D[x%N] = j P.append(x) x = (x + A[x%N]) j += 1 cycle = j - D[x%N] init = D[x%N] cyclesum = x - P[x%N] for K in Query: if K < init: ans = P[K] else: ans = P[(K-init)%cycle+init] + (K//cycle)*cyclesum print(ans)