結果

問題 No.1097 Remainder Operation
ユーザー rlangevinrlangevin
提出日時 2023-02-27 22:42:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 849 ms / 2,000 ms
コード長 598 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 329,152 KB
最終ジャッジ日時 2023-10-13 07:05:24
合計ジャッジ時間 13,536 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,260 KB
testcase_01 AC 69 ms
71,260 KB
testcase_02 AC 80 ms
76,344 KB
testcase_03 AC 81 ms
76,372 KB
testcase_04 AC 81 ms
76,276 KB
testcase_05 AC 83 ms
76,344 KB
testcase_06 AC 80 ms
76,352 KB
testcase_07 AC 159 ms
103,332 KB
testcase_08 AC 154 ms
103,328 KB
testcase_09 AC 157 ms
103,632 KB
testcase_10 AC 154 ms
102,832 KB
testcase_11 AC 157 ms
102,940 KB
testcase_12 AC 822 ms
322,904 KB
testcase_13 AC 820 ms
321,072 KB
testcase_14 AC 839 ms
320,984 KB
testcase_15 AC 849 ms
319,404 KB
testcase_16 AC 835 ms
326,360 KB
testcase_17 AC 687 ms
329,152 KB
testcase_18 AC 331 ms
185,624 KB
testcase_19 AC 692 ms
297,736 KB
testcase_20 AC 672 ms
297,752 KB
testcase_21 AC 511 ms
185,624 KB
testcase_22 AC 527 ms
185,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int, readline().split()))
Q = int(readline())
dp1 = [[0] * N for i in range(61)]
dp2 = [[0] * N for i in range(61)]
for i in range(N):
    dp1[0][i] = (i + A[i]) % N
    dp2[0][i] = A[i]
    
for n in range(60):
    for i in range(N):
        dp1[n + 1][i] = dp1[n][dp1[n][i]]
        dp2[n + 1][i] = dp2[n][i] + dp2[n][dp1[n][i]]

for _ in range(Q):
    K = int(readline())
    now = 0
    ans = 0
    for i in range(60):
        if (K >> i) & 1:
            ans += dp2[i][now]
            now = dp1[i][now]
    print(ans)
0