結果

問題 No.1097 Remainder Operation
コンテスト
ユーザー tktk_snsn
提出日時 2020-12-15 23:26:04
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
RE  
実行時間 -
コード長 776 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 487 ms
コンパイル使用メモリ 20,696 KB
実行使用メモリ 25,528 KB
最終ジャッジ日時 2026-04-08 14:55:40
合計ジャッジ時間 7,326 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from itertools import accumulate
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

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

seen = [0] * N
first = [0]
second = [0]

x = 0
while True:
    i = x % N
    if seen[i] == 0:
        first.append(A[i])
        x += A[i]
        seen[i] = 1
    elif seen[i] == 1:
        second.append(A[i])
        x += A[i]
        seen[i] = 2
    elif seen[i] >= 2:
        break

F = list(accumulate(first))
S = list(accumulate(second))
LF = len(F) - 1
LS = len(S) - 1


def cnt(k):
    if k <= len(F):
        return F[k]

    res = F[LF]
    k -= LF

    d, m = divmod(k, LS)
    res += d * S[LS]
    res += S[m]
    return res


Q = int(input())
for _ in range(Q):
    k = int(input())
    print(cnt(k))
0