結果

問題 No.1097 Remainder Operation
コンテスト
ユーザー yuly3
提出日時 2020-07-26 18:47:59
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 805 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 693 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 122,256 KB
最終ジャッジ日時 2026-03-17 21:10:44
合計ジャッジ時間 4,839 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    A = list(map(int, rl().split()))
    Q = int(rl())
    K = [int(rl()) for _ in range(Q)]
    
    X = 0
    counter = dict()
    cnt_to_x = {0: 0}
    cnt = 0
    while 1:
        cnt += 1
        r = X % N
        X += A[r]
        if r in counter:
            a = counter[r]
            b = cnt - counter[r]
            d = X - cnt_to_x[a]
            break
        else:
            counter[r] = cnt
            cnt_to_x[cnt] = X
    
    ans = []
    for ki in K:
        if ki <= a:
            ans.append(cnt_to_x[ki])
        else:
            roop, rem = divmod(ki - a, b)
            ans.append(roop * d + cnt_to_x[a + rem])
    print(*ans, sep='\n')


if __name__ == '__main__':
    solve()
0