結果

問題 No.1097 Remainder Operation
ユーザー brthyyjpbrthyyjp
提出日時 2020-09-25 03:47:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 248 ms / 2,000 ms
コード長 604 bytes
コンパイル時間 993 ms
コンパイル使用メモリ 86,772 KB
実行使用メモリ 108,784 KB
最終ジャッジ日時 2023-09-10 14:20:58
合計ジャッジ時間 6,264 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,124 KB
testcase_01 AC 71 ms
71,208 KB
testcase_02 AC 73 ms
71,312 KB
testcase_03 AC 73 ms
71,324 KB
testcase_04 AC 72 ms
71,332 KB
testcase_05 AC 73 ms
71,312 KB
testcase_06 AC 72 ms
70,944 KB
testcase_07 AC 248 ms
76,640 KB
testcase_08 AC 90 ms
76,604 KB
testcase_09 AC 88 ms
76,772 KB
testcase_10 AC 89 ms
76,696 KB
testcase_11 AC 88 ms
76,640 KB
testcase_12 AC 143 ms
90,820 KB
testcase_13 AC 138 ms
90,936 KB
testcase_14 AC 136 ms
90,696 KB
testcase_15 AC 136 ms
90,992 KB
testcase_16 AC 136 ms
90,572 KB
testcase_17 AC 131 ms
90,692 KB
testcase_18 AC 152 ms
107,136 KB
testcase_19 AC 157 ms
108,784 KB
testcase_20 AC 155 ms
108,736 KB
testcase_21 AC 155 ms
108,028 KB
testcase_22 AC 154 ms
107,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = sys.stdin.buffer.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n = int(input())
A = list(map(int, input().split()))
X = [0]*(n+2)
used = {}
x = 0
X[0] = x
for i in range(n+1):
    r = x%n
    x += A[r]
    X[i+1] = x
    if r in used:
        c = i-used[r]
        t = used[r]
        break
    else:
        used[r] = i

cum = X[t:t+c+1]
s = cum[-1]-cum[0]

Q = int(input())
for i in range(Q):
    k = int(input())
    if k < t:
        print(X[k])
    else:
        q, r = divmod(k-t, c)
        ans = X[t]+s*q+cum[r]-cum[0]
        print(ans)
0