結果

問題 No.1097 Remainder Operation
ユーザー convexineqconvexineq
提出日時 2020-06-26 22:05:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 457 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 87,300 KB
実行使用メモリ 167,208 KB
最終ジャッジ日時 2023-09-18 04:43:01
合計ジャッジ時間 7,052 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,128 KB
testcase_01 AC 70 ms
71,000 KB
testcase_02 AC 78 ms
75,700 KB
testcase_03 AC 79 ms
75,696 KB
testcase_04 AC 77 ms
75,592 KB
testcase_05 AC 79 ms
75,920 KB
testcase_06 AC 79 ms
75,660 KB
testcase_07 AC 108 ms
83,736 KB
testcase_08 AC 113 ms
83,820 KB
testcase_09 AC 107 ms
83,788 KB
testcase_10 AC 108 ms
83,680 KB
testcase_11 AC 108 ms
83,640 KB
testcase_12 AC 338 ms
163,204 KB
testcase_13 AC 357 ms
163,188 KB
testcase_14 AC 360 ms
163,324 KB
testcase_15 AC 372 ms
163,168 KB
testcase_16 AC 348 ms
163,240 KB
testcase_17 AC 281 ms
162,568 KB
testcase_18 AC 274 ms
167,208 KB
testcase_19 AC 313 ms
166,836 KB
testcase_20 AC 315 ms
166,740 KB
testcase_21 AC 456 ms
167,084 KB
testcase_22 AC 457 ms
166,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n, = map(int,readline().split())
*a, = map(int,readline().split())


dist = [a[:]]
nxt = [[(i+a[i])%n for i in range(n)]]

#print(nxt)
#print(dist)

for _ in range(40):
    res = [dist[-1][nxt[-1][i]] + dist[-1][i] for i in range(n)]
    dist.append(res)
    res = [nxt[-1][nxt[-1][i]] for i in range(n)]
    nxt.append(res)

#print(nxt[:2])
#print(dist[:2])

q,*k = map(int,read().split())
for ki in k:
    d = 0
    x = 0
    i = 0
    for m in range(40,-1,-1):
        if i + (1<<m) <= ki:
            d += dist[m][x]
            x = nxt[m][x]
            i += 1<<m
    
    print(d)            
    
    





0