結果

問題 No.1767 BLUE to RED
ユーザー kyskys
提出日時 2021-11-26 23:16:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 968 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 87,296 KB
実行使用メモリ 134,468 KB
最終ジャッジ日時 2023-09-12 05:34:31
合計ジャッジ時間 6,837 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,344 KB
testcase_01 AC 70 ms
71,664 KB
testcase_02 AC 71 ms
71,408 KB
testcase_03 AC 71 ms
71,332 KB
testcase_04 AC 74 ms
71,692 KB
testcase_05 AC 79 ms
75,496 KB
testcase_06 AC 74 ms
75,300 KB
testcase_07 AC 88 ms
77,036 KB
testcase_08 AC 89 ms
76,908 KB
testcase_09 AC 221 ms
96,928 KB
testcase_10 AC 265 ms
117,340 KB
testcase_11 AC 226 ms
101,004 KB
testcase_12 AC 228 ms
96,672 KB
testcase_13 AC 288 ms
122,188 KB
testcase_14 AC 316 ms
134,172 KB
testcase_15 AC 305 ms
134,180 KB
testcase_16 AC 312 ms
134,276 KB
testcase_17 AC 320 ms
134,420 KB
testcase_18 AC 302 ms
134,024 KB
testcase_19 AC 308 ms
134,220 KB
testcase_20 AC 303 ms
134,300 KB
testcase_21 AC 314 ms
134,468 KB
testcase_22 AC 311 ms
134,204 KB
testcase_23 AC 310 ms
134,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
def iinput(): return int(input())
def sinput(): return input().rstrip()
def i0input(): return int(input()) - 1
def linput(): return list(input().split())
def liinput(): return list(map(int, input().split()))
def miinput(): return map(int, input().split())
def li0input(): return list(map(lambda x: int(x) - 1, input().split()))
def mi0input(): return map(lambda x: int(x) - 1, input().split())
INF = 10**20
MOD = 1000000007

from bisect import bisect_left

N, M = liinput()
A = liinput()
B = liinput()
ans = 0
if A[0] > B[0]:
    ans += A[0] - B[0]
if A[-1] < B[-1]:
    ans += B[-1] - A[-1]
if N == 1:
    print(ans)
    exit()

for a1, a2 in zip(A[:-1], A[1:]):
    idx1 = bisect_left(B, a1)
    idx2 = bisect_left(B, a2)
    m = INF
    tmp = [a1]
    for i in range(idx1, idx2):
        tmp.append(B[i])
    tmp.append(a2)
    for b1, b2 in zip(tmp[:-1], tmp[1:]):
        m = min(m, b1 - a1 + a2 - b2)
    ans += m
print(ans)
0