結果
| 問題 | No.953 席 |
| コンテスト | |
| ユーザー |
mkawa2
|
| 提出日時 | 2021-03-30 18:44:47 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,357 ms / 2,000 ms |
| コード長 | 1,946 bytes |
| 記録 | |
| コンパイル時間 | 83 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 37,512 KB |
| 最終ジャッジ日時 | 2024-11-30 18:00:15 |
| 合計ジャッジ時間 | 26,107 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7
from heapq import *
from collections import deque
n, k1, k2 = LI()
seat = [False]*(n+2)
ent = (k1*2+k2)/3
vac = []
for j in range(1, n+1):
heappush(vac, (0, abs(j-ent), j))
wait = deque()
outin = []
q = II()
ans = [-1]*q
bb = [-1]*q
for i in range(q):
a, b = LI()
bb[i] = b
heappush(outin, (a, 1, i))
while outin:
t, op, i = heappop(outin)
if op:
wait.append(i)
else:
j = i
seat[j] = False
if seat[j-1] or seat[j+1]:
heappush(vac, (1, abs(j-ent), j))
else:
heappush(vac, (0, abs(j-ent), j))
if j-1 >= 1 and seat[j-1] == False and seat[j-2] == False:
heappush(vac, (0, abs(j-1-ent), j-1))
if j+1 <= n and seat[j+1] == False and seat[j+2] == False:
heappush(vac, (0, abs(j+1-ent), j+1))
if outin and t == outin[0][0]: continue
while wait and vac:
side, d, j = heappop(vac)
if seat[j]:
continue
if side == 0 and (seat[j-1] or seat[j+1]):
heappush(vac, (1, d, j))
continue
i = wait.popleft()
seat[j] = True
ans[i] = j
heappush(outin, (t+bb[i], 0, j))
# print(t, seat, wait, outin)
print(*ans, sep="\n")
mkawa2