結果

問題 No.1097 Remainder Operation
ユーザー c-yanc-yan
提出日時 2020-06-26 23:16:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 318 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 10,696 KB
実行使用メモリ 21,552 KB
最終ジャッジ日時 2023-09-18 07:48:40
合計ジャッジ時間 5,767 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,800 KB
testcase_01 AC 15 ms
7,724 KB
testcase_02 AC 15 ms
7,752 KB
testcase_03 AC 15 ms
7,740 KB
testcase_04 AC 15 ms
7,724 KB
testcase_05 AC 15 ms
7,864 KB
testcase_06 AC 15 ms
7,740 KB
testcase_07 AC 37 ms
9,228 KB
testcase_08 AC 38 ms
9,208 KB
testcase_09 AC 37 ms
9,336 KB
testcase_10 AC 37 ms
9,104 KB
testcase_11 AC 37 ms
9,212 KB
testcase_12 AC 248 ms
19,668 KB
testcase_13 AC 254 ms
19,576 KB
testcase_14 AC 254 ms
19,556 KB
testcase_15 AC 257 ms
19,628 KB
testcase_16 AC 255 ms
19,732 KB
testcase_17 AC 253 ms
19,680 KB
testcase_18 AC 297 ms
21,400 KB
testcase_19 AC 298 ms
21,552 KB
testcase_20 AC 301 ms
21,384 KB
testcase_21 AC 317 ms
21,412 KB
testcase_22 AC 318 ms
21,508 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
#print(loop_start)
#print(loop_len)
#print(b)
#print(c)

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(a)
        #print(K)
        #print(c[-1] - c[loop_start])
        print(c[K] + a * (c[-1] - c[loop_start]))
0