結果

問題 No.1097 Remainder Operation
ユーザー AEnAEn
提出日時 2022-05-22 19:23:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 469 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 114,936 KB
最終ジャッジ日時 2023-10-20 17:14:09
合計ジャッジ時間 8,313 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,572 KB
testcase_01 AC 38 ms
53,572 KB
testcase_02 AC 40 ms
53,572 KB
testcase_03 AC 39 ms
53,572 KB
testcase_04 AC 38 ms
53,572 KB
testcase_05 AC 38 ms
53,572 KB
testcase_06 AC 38 ms
53,572 KB
testcase_07 AC 99 ms
76,136 KB
testcase_08 AC 101 ms
76,144 KB
testcase_09 AC 100 ms
76,132 KB
testcase_10 AC 99 ms
76,140 KB
testcase_11 AC 100 ms
76,136 KB
testcase_12 AC 305 ms
89,540 KB
testcase_13 AC 308 ms
89,276 KB
testcase_14 AC 305 ms
89,540 KB
testcase_15 AC 303 ms
89,540 KB
testcase_16 AC 303 ms
89,540 KB
testcase_17 AC 311 ms
89,652 KB
testcase_18 AC 327 ms
114,936 KB
testcase_19 AC 330 ms
114,936 KB
testcase_20 AC 331 ms
114,936 KB
testcase_21 AC 338 ms
114,936 KB
testcase_22 AC 342 ms
114,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

b, c, B = [], [], set()
X = 0
while True:
    r = X%N
    X += A[r]
    if r in B:
        id = b.index(r)
        roop = len(b)-id
        sm = X-c[id]
        break
    else:
        B.add(r)
        b.append(r)
        c.append(X)

Q = int(input())
for i in range(Q):
    K = int(input())
    if K <= len(b):
        print(c[K-1])
    else:
        print(c[id]+sm*((K-1-id)//roop) + c[id+((K-1-id)%roop)]-c[id])

0