結果

問題 No.1767 BLUE to RED
ユーザー ygd.ygd.
提出日時 2021-12-02 21:24:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 448 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 35,584 KB
最終ジャッジ日時 2023-09-18 10:38:33
合計ジャッジ時間 7,763 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,756 KB
testcase_01 AC 17 ms
7,836 KB
testcase_02 AC 17 ms
7,800 KB
testcase_03 AC 15 ms
7,736 KB
testcase_04 AC 16 ms
7,808 KB
testcase_05 AC 17 ms
7,760 KB
testcase_06 AC 16 ms
7,856 KB
testcase_07 AC 17 ms
7,760 KB
testcase_08 AC 17 ms
7,820 KB
testcase_09 AC 262 ms
23,480 KB
testcase_10 AC 341 ms
26,868 KB
testcase_11 AC 270 ms
25,364 KB
testcase_12 AC 257 ms
23,392 KB
testcase_13 AC 378 ms
28,168 KB
testcase_14 AC 447 ms
35,456 KB
testcase_15 AC 445 ms
35,468 KB
testcase_16 AC 444 ms
35,408 KB
testcase_17 AC 446 ms
35,360 KB
testcase_18 AC 444 ms
35,516 KB
testcase_19 AC 447 ms
35,460 KB
testcase_20 AC 448 ms
35,400 KB
testcase_21 AC 447 ms
35,516 KB
testcase_22 AC 447 ms
35,520 KB
testcase_23 AC 445 ms
35,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline #文字列につけてはダメ
input = sys.stdin.buffer.readline #文字列につけてはダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict
#from collections import deque
#import copy

def main():
    N,M = map(int,input().split()); INF = pow(10,18)
    A = [-INF] + list(map(int,input().split())) + [INF]
    B = list(map(int,input().split()))
    ans = 0
    j = 0
    for i in range(N+1):
        if j >= M: break
        temp = []
        left,right = A[i:i+2]
        while j < M and B[j] < right:
            temp.append(B[j])
            j += 1
        #print(temp,left,right)
        L = [0]; R = [0]
        for k in range(len(temp)):
            L.append(temp[k] - left)
            R.append(right - temp[-1-k])
        R.reverse()
        #print(L,R)
        mn = INF
        for p,q in zip(L,R):
            mn = min(mn, p+q)
        ans += mn
    print(ans)


if __name__ == '__main__':
    main()
0