結果

問題 No.1097 Remainder Operation
ユーザー AEn
提出日時 2022-05-22 19:23:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 469 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 115,456 KB
最終ジャッジ日時 2024-09-20 12:48:40
合計ジャッジ時間 8,152 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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