結果

問題 No.1097 Remainder Operation
ユーザー 👑 H20H20
提出日時 2021-10-14 08:56:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 733 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 619 ms
コンパイル使用メモリ 81,584 KB
実行使用メモリ 158,144 KB
最終ジャッジ日時 2023-10-17 19:17:53
合計ジャッジ時間 12,260 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,756 KB
testcase_01 AC 38 ms
53,792 KB
testcase_02 AC 48 ms
62,108 KB
testcase_03 AC 47 ms
62,236 KB
testcase_04 AC 47 ms
62,236 KB
testcase_05 AC 47 ms
62,108 KB
testcase_06 AC 47 ms
62,236 KB
testcase_07 AC 124 ms
83,400 KB
testcase_08 AC 125 ms
83,516 KB
testcase_09 AC 120 ms
83,424 KB
testcase_10 AC 123 ms
83,420 KB
testcase_11 AC 122 ms
83,420 KB
testcase_12 AC 617 ms
157,792 KB
testcase_13 AC 653 ms
157,792 KB
testcase_14 AC 670 ms
157,792 KB
testcase_15 AC 723 ms
157,792 KB
testcase_16 AC 652 ms
157,792 KB
testcase_17 AC 479 ms
158,144 KB
testcase_18 AC 468 ms
156,572 KB
testcase_19 AC 591 ms
156,868 KB
testcase_20 AC 562 ms
156,520 KB
testcase_21 AC 701 ms
156,520 KB
testcase_22 AC 733 ms
156,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

N = int(input())
A = list(map(int,input().split()))
Q = int(input())

# 二次元配列作成
nex = []
nsum = []

for _ in range(int(math.log2(10**13))):
    l1 = [0] * N
    l2 = [0] * N
    nex.append(l1)
    nsum.append(l2)

# dv[0][0:X]を初期化
for n in range(N):
    nex[0][n] = (n+A[n])%N
    nsum[0][n] = A[n]

# ダブリングで表を構築
for k in range(1, int(math.log2(10**13))):
    for n in range(N):
        nex[k][n] = nex[k - 1][nex[k - 1][n]]
        nsum[k][n] = nsum[k - 1][n] + nsum[k - 1][nex[k - 1][n]]

for _ in range(Q):
    K = int(input())
    a = []
    for i in range(int(math.log2(K)) + 1):
        if K>>i & 1:
            a.append(i)

    ans = 0
    X = 0
    for i in a:
        ans += nsum[i][X]
        X = nex[i][X]
    print(ans)
0