結果
| 問題 |
No.1097 Remainder Operation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-29 13:23:51 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 329 ms / 2,000 ms |
| コード長 | 971 bytes |
| コンパイル時間 | 1,115 ms |
| コンパイル使用メモリ | 82,220 KB |
| 実行使用メモリ | 114,276 KB |
| 最終ジャッジ日時 | 2024-09-30 15:02:28 |
| 合計ジャッジ時間 | 7,772 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
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()