結果

問題 No.1767 BLUE to RED
ユーザー lloyzlloyz
提出日時 2021-11-27 00:04:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 604 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 41,824 KB
最終ジャッジ日時 2023-09-12 05:43:57
合計ジャッジ時間 10,090 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,944 KB
testcase_01 AC 17 ms
7,940 KB
testcase_02 AC 17 ms
7,960 KB
testcase_03 AC 16 ms
8,004 KB
testcase_04 AC 18 ms
8,436 KB
testcase_05 AC 18 ms
8,024 KB
testcase_06 AC 17 ms
8,256 KB
testcase_07 AC 18 ms
7,960 KB
testcase_08 AC 19 ms
8,068 KB
testcase_09 AC 328 ms
27,908 KB
testcase_10 AC 402 ms
35,132 KB
testcase_11 AC 376 ms
28,024 KB
testcase_12 AC 331 ms
27,188 KB
testcase_13 AC 440 ms
36,760 KB
testcase_14 AC 595 ms
41,696 KB
testcase_15 AC 596 ms
41,644 KB
testcase_16 AC 595 ms
41,772 KB
testcase_17 AC 601 ms
41,752 KB
testcase_18 AC 598 ms
41,824 KB
testcase_19 AC 595 ms
41,660 KB
testcase_20 AC 600 ms
41,556 KB
testcase_21 AC 598 ms
41,672 KB
testcase_22 AC 604 ms
41,560 KB
testcase_23 AC 595 ms
41,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left

n, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

L = [[] for _ in range(n + 1)]
for i in range(m):
    ind = bisect_left(A, B[i])
    L[ind].append(B[i])
ans = 0
for i in range(n + 1):
    if not L[i]:
        continue
    if i == 0:
        ans += A[0] - L[0][0]
    elif i == n:
        ans += L[i][-1] - A[n - 1]
    else:
        if len(L[i]) == 1:
            ans += min(L[i][0] - A[i - 1], A[i] - L[i][0])
        else:
            min_d = 10**10
            min_d = min(min_d, L[i][-1] - A[i - 1])
            min_d = min(min_d, A[i] - L[i][0])
            for j in range(len(L[i]) - 1):
                tmp = L[i][j] - A[i - 1] + A[i] - L[i][j + 1]
                min_d = min(min_d, tmp)
            ans += min_d
print(ans)
0