結果

問題 No.1097 Remainder Operation
ユーザー kohei2019kohei2019
提出日時 2022-07-22 00:12:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 602 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 99,724 KB
最終ジャッジ日時 2023-09-16 08:40:30
合計ジャッジ時間 5,283 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,312 KB
testcase_01 AC 72 ms
71,112 KB
testcase_02 AC 72 ms
71,220 KB
testcase_03 AC 72 ms
71,132 KB
testcase_04 AC 72 ms
71,216 KB
testcase_05 AC 73 ms
71,372 KB
testcase_06 AC 75 ms
71,120 KB
testcase_07 AC 113 ms
77,472 KB
testcase_08 AC 111 ms
77,396 KB
testcase_09 AC 110 ms
77,664 KB
testcase_10 AC 111 ms
77,432 KB
testcase_11 AC 111 ms
77,704 KB
testcase_12 AC 173 ms
91,444 KB
testcase_13 AC 173 ms
91,316 KB
testcase_14 AC 177 ms
91,568 KB
testcase_15 AC 171 ms
91,500 KB
testcase_16 AC 172 ms
91,500 KB
testcase_17 AC 173 ms
91,568 KB
testcase_18 AC 185 ms
99,364 KB
testcase_19 AC 187 ms
99,300 KB
testcase_20 AC 186 ms
99,660 KB
testcase_21 AC 192 ms
99,292 KB
testcase_22 AC 190 ms
99,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
lsA = list(map(int,input().split()))
Q = int(input())
lsQ = [int(input()) for i in range(Q)]

r = 0
x = 0
used = set()
ll = [0]
while not(r in used):
    used.add(r)
    x += lsA[r]
    ll.append(x)
    r = (x)%N

st = 0
for i in range(len(ll)):
    if ll[i] % N == r:
        st = i
        break

rooppoint = ll[-1]-ll[st]
rooplen = len(ll)-1-st

for i in range(Q):
    q = lsQ[i]
    if q <= st:
        print(ll[q])
        continue
    else:
        p = q-st
        roopn = p//rooplen
        roopadd = p%rooplen
        print(ll[st]+roopn*rooppoint+(ll[st+roopadd]-ll[st]))
    
0