結果

問題 No.808 Kaiten Sushi?
ユーザー mkawa2mkawa2
提出日時 2022-03-02 22:20:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,549 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 111,448 KB
最終ジャッジ日時 2023-09-23 13:10:49
合計ジャッジ時間 17,821 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,376 KB
testcase_01 AC 78 ms
71,420 KB
testcase_02 AC 78 ms
71,348 KB
testcase_03 AC 78 ms
71,140 KB
testcase_04 WA -
testcase_05 AC 79 ms
71,288 KB
testcase_06 AC 80 ms
71,496 KB
testcase_07 AC 93 ms
76,644 KB
testcase_08 AC 93 ms
76,520 KB
testcase_09 AC 154 ms
78,920 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 140 ms
78,684 KB
testcase_13 AC 134 ms
78,968 KB
testcase_14 AC 100 ms
76,656 KB
testcase_15 AC 156 ms
79,168 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 96 ms
75,812 KB
testcase_21 AC 91 ms
76,148 KB
testcase_22 AC 95 ms
75,788 KB
testcase_23 AC 127 ms
92,808 KB
testcase_24 AC 119 ms
88,520 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 292 ms
94,460 KB
testcase_34 AC 317 ms
96,756 KB
testcase_35 WA -
testcase_36 AC 314 ms
94,108 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 315 ms
107,428 KB
testcase_40 AC 177 ms
83,056 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 249 ms
85,828 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 242 ms
83,520 KB
testcase_47 WA -
testcase_48 AC 325 ms
111,164 KB
testcase_49 AC 320 ms
111,320 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 78 ms
71,464 KB
testcase_55 AC 80 ms
71,308 KB
testcase_56 AC 76 ms
71,400 KB
testcase_57 AC 185 ms
86,960 KB
testcase_58 AC 215 ms
93,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
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 = (1 << 63)-1
# inf = (1 << 31)-1
md = 10**9+7
# md = 998244353

from heapq import *

n, l = LI()
xx = LI()
yy = LI()
xt = []
for x in xx: xt.append((x, 0))
for x in yy: xt.append((x, 1))
xt.sort(key=lambda x: x[0])

gg = []
tt = []

for x, t in xt:
    if not tt or tt[-1] != t:
        gg.append([])
        tt.append(t)
    heappush(gg[-1], -x)
# pDB(gg)
# pDB(tt)

if tt[0] == tt[-1]:
    g = gg.pop()
    for x in g:
        heappush(gg[0], x+l)
# pDB(gg)
# pDB(tt)

ans = 0
now = 0
while gg:
    ngg = []
    ntt = []
    for t, g in zip(tt,gg):
        x = -heappop(g)
        ans += (x-now)%l
        now = x
        if g:
            if not ntt or ntt[-1] != t:
                ntt.append(t)
                ngg.append(g)
            else:
                for x in g:
                    heappush(ngg[-1], x)
        # pDB(ngg)
        # pDB(ntt)
    tt, gg = ntt, ngg

print(ans)
0