結果

問題 No.1097 Remainder Operation
ユーザー c-yanc-yan
提出日時 2020-06-27 05:03:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 321 ms / 2,000 ms
コード長 611 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 10,752 KB
実行使用メモリ 22,172 KB
最終ジャッジ日時 2023-09-18 18:52:24
合計ジャッジ時間 5,402 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,768 KB
testcase_01 AC 16 ms
7,784 KB
testcase_02 AC 16 ms
7,760 KB
testcase_03 AC 15 ms
7,792 KB
testcase_04 AC 15 ms
7,804 KB
testcase_05 AC 17 ms
7,864 KB
testcase_06 AC 17 ms
7,760 KB
testcase_07 AC 38 ms
9,280 KB
testcase_08 AC 38 ms
9,304 KB
testcase_09 AC 38 ms
9,280 KB
testcase_10 AC 39 ms
9,252 KB
testcase_11 AC 39 ms
9,268 KB
testcase_12 AC 252 ms
19,596 KB
testcase_13 AC 258 ms
19,576 KB
testcase_14 AC 258 ms
19,756 KB
testcase_15 AC 258 ms
19,640 KB
testcase_16 AC 252 ms
19,764 KB
testcase_17 AC 256 ms
19,648 KB
testcase_18 AC 306 ms
22,024 KB
testcase_19 AC 303 ms
22,016 KB
testcase_20 AC 311 ms
21,956 KB
testcase_21 AC 317 ms
22,172 KB
testcase_22 AC 321 ms
22,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
readline = stdin.readline

N = int(readline())
A = list(map(int, readline().split()))

X = 0
b = [-1]
c = [X]
used = set()
while True:
    r = X % N
    X += A[r]
    if r in used:
        break
    used.add(r)
    b.append(r)
    c.append(X)
b.append(r)
c.append(X)
loop_start = b.index(b[-1])
loop_len = len(b) - loop_start - 1

Q = int(readline())
for _ in range(Q):
    K = int(readline())
    if K < len(b):
        print(c[K])
    else:
        K -= loop_start
        a = K // loop_len
        K %= loop_len
        K += loop_start
        print(c[K] + a * (c[-1] - c[loop_start]))
0