結果

問題 No.714 回転寿司屋のシミュレート
ユーザー GrayCoder
提出日時 2018-07-14 12:49:40
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 848 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-10-09 16:25:46
合計ジャッジ時間 2,628 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from heapq import heappush, heappop
from sys import stdin, stdout
input = lambda: stdin.readline().rstrip()
write = stdout.write

def main():
    N = int(input())
    U = [tuple(input().split()) for _ in [0] * N]

    sushi = defaultdict(list)
    seat = [[] for _ in [0] * 21]
    for s in U:
        if s[0] == '0':
            i = int(s[1])
            for t in s[3:]:
                heappush(sushi[t], i)
                seat[i].append(t)
        elif s[0] == '1':
            while sushi[s[1]]:
                i = heappop(sushi[s[1]])
                if s[1] in seat[i]:
                    print(i)
                    j = seat[i].index(s[1])
                    seat[i][j] = ''
                    break
            else:
                print(-1)
        else:
            seat[int(s[1])] = []

main()
0