結果

問題 No.1097 Remainder Operation
ユーザー wattaiheiwattaihei
提出日時 2020-06-26 22:53:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 468 bytes
コンパイル時間 489 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 90,448 KB
最終ジャッジ日時 2023-09-18 06:52:28
合計ジャッジ時間 5,016 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,288 KB
testcase_01 AC 69 ms
71,372 KB
testcase_02 AC 68 ms
71,392 KB
testcase_03 AC 68 ms
71,400 KB
testcase_04 AC 71 ms
71,292 KB
testcase_05 AC 70 ms
71,372 KB
testcase_06 AC 70 ms
71,444 KB
testcase_07 AC 88 ms
76,772 KB
testcase_08 AC 88 ms
77,056 KB
testcase_09 AC 88 ms
76,820 KB
testcase_10 AC 87 ms
77,232 KB
testcase_11 AC 87 ms
77,016 KB
testcase_12 AC 139 ms
90,252 KB
testcase_13 AC 140 ms
90,384 KB
testcase_14 AC 142 ms
90,448 KB
testcase_15 AC 142 ms
90,184 KB
testcase_16 AC 140 ms
90,036 KB
testcase_17 AC 137 ms
90,396 KB
testcase_18 AC 133 ms
89,264 KB
testcase_19 AC 143 ms
89,124 KB
testcase_20 AC 141 ms
89,256 KB
testcase_21 AC 142 ms
89,140 KB
testcase_22 AC 142 ms
89,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[D[x%N]]

for K in Query:
    if K < init:
        ans = P[K]
    else:
        ans = P[(K-init)%cycle+init] + ((K-init)//cycle)*cyclesum
    print(ans)
0