結果

問題 No.1097 Remainder Operation
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-15 23:29:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 772 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 11,968 KB
実行使用メモリ 20,996 KB
最終ジャッジ日時 2023-10-20 06:55:52
合計ジャッジ時間 4,907 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,132 KB
testcase_01 AC 28 ms
10,132 KB
testcase_02 AC 27 ms
10,136 KB
testcase_03 AC 28 ms
10,136 KB
testcase_04 AC 29 ms
10,136 KB
testcase_05 AC 29 ms
10,136 KB
testcase_06 AC 28 ms
10,136 KB
testcase_07 AC 44 ms
11,060 KB
testcase_08 AC 45 ms
11,060 KB
testcase_09 AC 45 ms
11,060 KB
testcase_10 AC 44 ms
11,060 KB
testcase_11 AC 44 ms
11,060 KB
testcase_12 AC 199 ms
19,392 KB
testcase_13 AC 203 ms
19,392 KB
testcase_14 AC 202 ms
19,392 KB
testcase_15 AC 203 ms
19,392 KB
testcase_16 AC 197 ms
19,392 KB
testcase_17 AC 198 ms
19,392 KB
testcase_18 AC 277 ms
20,996 KB
testcase_19 AC 237 ms
16,244 KB
testcase_20 AC 239 ms
16,244 KB
testcase_21 AC 273 ms
18,620 KB
testcase_22 AC 276 ms
18,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 <= LF:
        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