結果

問題 No.1767 BLUE to RED
ユーザー 👑 H20H20
提出日時 2021-11-26 23:15:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,131 ms / 2,000 ms
コード長 618 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 148,072 KB
最終ジャッジ日時 2023-09-12 05:33:41
合計ジャッジ時間 17,907 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,544 KB
testcase_01 AC 84 ms
71,232 KB
testcase_02 AC 79 ms
71,380 KB
testcase_03 AC 79 ms
71,324 KB
testcase_04 AC 111 ms
77,508 KB
testcase_05 AC 116 ms
77,688 KB
testcase_06 AC 81 ms
71,292 KB
testcase_07 AC 95 ms
76,296 KB
testcase_08 AC 115 ms
77,308 KB
testcase_09 AC 708 ms
107,880 KB
testcase_10 AC 799 ms
123,316 KB
testcase_11 AC 824 ms
116,268 KB
testcase_12 AC 708 ms
108,028 KB
testcase_13 AC 814 ms
130,836 KB
testcase_14 AC 1,124 ms
148,072 KB
testcase_15 AC 1,129 ms
147,268 KB
testcase_16 AC 1,078 ms
147,160 KB
testcase_17 AC 1,103 ms
147,060 KB
testcase_18 AC 1,088 ms
146,952 KB
testcase_19 AC 1,074 ms
147,588 KB
testcase_20 AC 1,097 ms
147,008 KB
testcase_21 AC 1,090 ms
147,772 KB
testcase_22 AC 1,089 ms
147,084 KB
testcase_23 AC 1,131 ms
147,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import bisect
N,M = map(int, input().split())
A = [-10**12]+list(map(int, input().split()))+[10**12]
B = list(map(int, input().split()))
SB = set()
d = []
for i in range(M):
    b = B[i]
    j = bisect.bisect(A,b)
    if A[j]-b>b-A[j-1]:
        heapq.heappush(d,(b-A[j-1],i))
    else:
        heapq.heappush(d,(A[j]-b,i))
ans = 0
while len(d):
    v,i = heapq.heappop(d)
    if not i in SB:
        ans+=v
        SB.add(i)
        if i>0 and not i-1 in SB:
            heapq.heappush(d,(B[i]-B[i-1],i-1))
        if i<M-1 and not i+1 in SB:
            heapq.heappush(d,(B[i+1]-B[i],i+1))
print(ans)


0