結果

問題 No.1097 Remainder Operation
ユーザー Coki628Coki628
提出日時 2020-11-21 00:37:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 487 ms / 2,000 ms
コード長 1,390 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 154,788 KB
最終ジャッジ日時 2023-09-30 20:22:45
合計ジャッジ時間 8,084 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,552 KB
testcase_01 AC 74 ms
71,772 KB
testcase_02 AC 84 ms
77,300 KB
testcase_03 AC 85 ms
77,188 KB
testcase_04 AC 83 ms
77,164 KB
testcase_05 AC 83 ms
77,344 KB
testcase_06 AC 83 ms
77,368 KB
testcase_07 AC 111 ms
84,356 KB
testcase_08 AC 117 ms
84,188 KB
testcase_09 AC 115 ms
84,668 KB
testcase_10 AC 115 ms
84,488 KB
testcase_11 AC 114 ms
84,160 KB
testcase_12 AC 365 ms
154,652 KB
testcase_13 AC 396 ms
154,568 KB
testcase_14 AC 395 ms
154,620 KB
testcase_15 AC 423 ms
154,364 KB
testcase_16 AC 379 ms
154,476 KB
testcase_17 AC 298 ms
154,788 KB
testcase_18 AC 287 ms
153,172 KB
testcase_19 AC 328 ms
153,136 KB
testcase_20 AC 333 ms
153,048 KB
testcase_21 AC 487 ms
153,100 KB
testcase_22 AC 487 ms
153,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for k in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for k in range(c)] for k in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10**9)
INF = 10**19
MOD = 10**9 + 7
EPS = 10**-10

def doubling(MAX, A):
    """ ダブリング """

    N = len(A)
    nxt = list2d(MAX, N, -1)
    sm = list2d(MAX, N, 0)
    for i, a in enumerate(A):
        nxt[0][i] = (i+a) % N
        sm[0][i] = a
    for k in range(1, MAX):
        for i in range(N):
            nxt[k][i] = nxt[k-1][nxt[k-1][i]]
            sm[k][i] = sm[k-1][i] + sm[k-1][nxt[k-1][i]]
    return (nxt, sm)

N = INT()
A = LIST()

MX = 40
nxt, sm = doubling(MX, A)

# x = cur = 0
# for i in range(10):
#     x += sm[0][cur]
#     cur = nxt[0][cur] % N
#     print(x, cur)

for _ in range(INT()):
    k = INT()
    x = cur = 0
    for i in range(MX-1, -1, -1):
        if k>>i & 1:
            x += sm[i][cur]
            cur = nxt[i][cur] % N
    print(x)
0