結果

問題 No.1097 Remainder Operation
ユーザー ttrttr
提出日時 2020-06-26 22:54:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 326 ms / 2,000 ms
コード長 454 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 82,252 KB
実行使用メモリ 94,472 KB
最終ジャッジ日時 2024-07-04 23:07:31
合計ジャッジ時間 6,422 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = [int(a) for a in input().split()]

L = [[-1, -1] for _ in range(N)]
X = 0
i = 0
cnt = 0
num = [0]*(N+1)
while L[i][0] < 0:
    cnt += 1
    X += A[i]
    num[cnt] = X
    L[i][0] = X
    L[i][1] = cnt
    i = X%N

t0 = L[i][1]
p0 = L[i][0]
t = cnt-L[i][1]+1
p = X-L[i][0]+A[i]
Q = int(input())
for _ in range(Q):
    K = int(input())
    if K <= t0:
        print(num[K])
    else:
        K -= t0
        print((K//t)*p+num[K%t+t0])
0