結果

問題 No.1767 BLUE to RED
ユーザー ygd.
提出日時 2021-12-02 21:24:10
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 565 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 38,188 KB
最終ジャッジ日時 2024-07-05 02:07:19
合計ジャッジ時間 9,340 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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