結果

問題 No.1097 Remainder Operation
ユーザー Chihaya_chanChihaya_chan
提出日時 2020-09-05 02:05:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 725 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 25,068 KB
最終ジャッジ日時 2023-08-17 21:15:23
合計ジャッジ時間 8,290 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,832 KB
testcase_01 AC 17 ms
7,852 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 318 ms
19,864 KB
testcase_18 AC 382 ms
24,876 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
querie = [int(input()) for i in range(Q)]

mod_set = set([0])
seq = [0]
now_value = 0
flag = True
while flag:
    V = now_value + A[now_value % N]
    if not V % N in mod_set:
        mod_set.add(V % N)
        seq.append(V)
        now_value = V
        continue
    else:
        flag = False
        seq.append(V)

L, R = 10**10, 0
modular = seq[-1] % N
for i in range(len(seq)):
    if seq[i] % N == modular:
        R = i
        L = min(L, i)
D = seq[R] - seq[L]
period = R-L


def solve(X):
    if X <= len(seq) - 1:
        return seq[X]
    else:
        u, v = divmod(X, period)
        return seq[v] + D*u


for q in querie:
    print(solve(q))
0