結果

問題 No.1097 Remainder Operation
ユーザー ThetaTheta
提出日時 2024-03-29 13:23:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 410 ms / 2,000 ms
コード長 971 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 113,796 KB
最終ジャッジ日時 2024-03-29 13:24:01
合計ジャッジ時間 8,808 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 40 ms
53,460 KB
testcase_03 AC 49 ms
53,460 KB
testcase_04 AC 40 ms
53,460 KB
testcase_05 AC 40 ms
53,460 KB
testcase_06 AC 40 ms
53,460 KB
testcase_07 AC 103 ms
76,104 KB
testcase_08 AC 104 ms
76,100 KB
testcase_09 AC 102 ms
76,104 KB
testcase_10 AC 103 ms
76,100 KB
testcase_11 AC 102 ms
76,100 KB
testcase_12 AC 322 ms
89,592 KB
testcase_13 AC 337 ms
89,464 KB
testcase_14 AC 322 ms
89,464 KB
testcase_15 AC 321 ms
89,592 KB
testcase_16 AC 347 ms
89,464 KB
testcase_17 AC 326 ms
89,788 KB
testcase_18 AC 372 ms
113,796 KB
testcase_19 AC 409 ms
113,796 KB
testcase_20 AC 385 ms
113,796 KB
testcase_21 AC 391 ms
113,796 KB
testcase_22 AC 410 ms
113,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys


def printe(*args, end="\n", **kwargs):
    print(*args, end=end, file=sys.stderr, **kwargs)


def main():
    N = int(input())
    A = list(map(int, input().split()))

    history_x = []
    history_mod = {}
    c_x = 0
    c_n = 0
    while (c_x % N) not in history_mod:
        history_x.append(c_x)
        history_mod[c_x % N] = c_n
        c_x += A[c_x % N]
        c_n += 1
    printe(history_mod)
    printe(history_x)
    loop_interval = c_n - history_mod[c_x % N]
    init = history_mod[c_x % N]
    printe(loop_interval, init, c_x)
    increase = c_x - history_x[init]

    for _ in range(int(input())):
        K = int(input())
        if K < init:
            print(history_x[K])
            continue
        loop_n = (K - init) // loop_interval
        loop_rest = (K - init) % loop_interval
        print(history_x[init] + increase * loop_n +
              history_x[init + loop_rest] - history_x[init])


if __name__ == "__main__":
    main()
0