結果

問題 No.1767 BLUE to RED
ユーザー rlangevinrlangevin
提出日時 2023-02-20 22:17:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 398 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 153,932 KB
最終ジャッジ日時 2023-09-28 17:43:36
合計ジャッジ時間 10,404 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,376 KB
testcase_01 AC 75 ms
71,428 KB
testcase_02 AC 77 ms
71,260 KB
testcase_03 AC 77 ms
71,480 KB
testcase_04 AC 77 ms
71,444 KB
testcase_05 AC 81 ms
75,428 KB
testcase_06 AC 76 ms
71,388 KB
testcase_07 AC 87 ms
76,712 KB
testcase_08 AC 92 ms
76,928 KB
testcase_09 AC 271 ms
115,660 KB
testcase_10 AC 344 ms
136,132 KB
testcase_11 AC 303 ms
122,992 KB
testcase_12 AC 280 ms
115,764 KB
testcase_13 AC 347 ms
153,932 KB
testcase_14 AC 384 ms
146,660 KB
testcase_15 AC 379 ms
146,616 KB
testcase_16 AC 398 ms
146,908 KB
testcase_17 AC 388 ms
146,880 KB
testcase_18 AC 384 ms
146,708 KB
testcase_19 AC 384 ms
146,840 KB
testcase_20 AC 395 ms
146,636 KB
testcase_21 AC 379 ms
147,844 KB
testcase_22 AC 382 ms
146,632 KB
testcase_23 AC 383 ms
146,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import *

def f(L):
    if L == []:
        return 0
    n = len(L)
    ind = bisect_right(A, L[0])
    pre = A[ind - 1]
    nex = A[ind]
    minv = min(nex - L[0], L[-1] - pre)
    for i in range(n - 1):
        val = L[i] - pre + nex - L[i + 1]
        minv = min(minv, val)
    return minv

N, M = map(int, input().split())
inf = 10 ** 18
A = [-inf] + list(map(int, input().split())) + [inf]
B = list(map(int, input().split()))
D = []
for a in A:
    D.append((a, 1))
for b in B:
    D.append((b, 0))
D.sort()

lst = []
ans = 0
for v, flag in D:
    if flag:
        ans += f(lst)
        lst = []
    else:
        lst.append(v)

print(ans)
0