結果

問題 No.953 席
ユーザー mkawa2mkawa2
提出日時 2021-03-30 18:44:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,336 ms / 2,000 ms
コード長 1,946 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 37,520 KB
最終ジャッジ日時 2024-05-07 21:31:20
合計ジャッジ時間 26,601 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
11,136 KB
testcase_01 AC 30 ms
11,008 KB
testcase_02 AC 811 ms
31,732 KB
testcase_03 AC 768 ms
31,144 KB
testcase_04 AC 809 ms
32,116 KB
testcase_05 AC 683 ms
31,620 KB
testcase_06 AC 819 ms
32,364 KB
testcase_07 AC 960 ms
34,328 KB
testcase_08 AC 1,185 ms
36,524 KB
testcase_09 AC 754 ms
33,528 KB
testcase_10 AC 278 ms
18,688 KB
testcase_11 AC 856 ms
30,260 KB
testcase_12 AC 1,065 ms
35,488 KB
testcase_13 AC 1,213 ms
37,224 KB
testcase_14 AC 1,005 ms
35,432 KB
testcase_15 AC 992 ms
34,916 KB
testcase_16 AC 1,022 ms
35,200 KB
testcase_17 AC 1,109 ms
35,200 KB
testcase_18 AC 1,057 ms
34,716 KB
testcase_19 AC 1,336 ms
37,496 KB
testcase_20 AC 1,066 ms
34,544 KB
testcase_21 AC 842 ms
32,560 KB
testcase_22 AC 1,059 ms
36,068 KB
testcase_23 AC 915 ms
33,420 KB
testcase_24 AC 931 ms
33,572 KB
testcase_25 AC 1,280 ms
37,520 KB
testcase_26 AC 624 ms
31,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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")
0