結果

問題 No.1767 BLUE to RED
ユーザー 👑 KazunKazun
提出日時 2021-11-26 22:50:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 86,688 KB
実行使用メモリ 140,424 KB
最終ジャッジ日時 2023-09-12 05:20:37
合計ジャッジ時間 7,130 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,136 KB
testcase_01 AC 75 ms
71,056 KB
testcase_02 AC 77 ms
71,404 KB
testcase_03 AC 79 ms
71,136 KB
testcase_04 AC 84 ms
75,264 KB
testcase_05 AC 86 ms
75,200 KB
testcase_06 AC 79 ms
71,408 KB
testcase_07 AC 88 ms
75,912 KB
testcase_08 AC 90 ms
76,532 KB
testcase_09 AC 225 ms
109,204 KB
testcase_10 AC 254 ms
110,176 KB
testcase_11 AC 236 ms
110,000 KB
testcase_12 AC 225 ms
108,508 KB
testcase_13 AC 276 ms
131,852 KB
testcase_14 AC 321 ms
139,872 KB
testcase_15 AC 315 ms
139,936 KB
testcase_16 AC 312 ms
140,424 KB
testcase_17 AC 311 ms
139,876 KB
testcase_18 AC 313 ms
140,064 KB
testcase_19 AC 315 ms
140,152 KB
testcase_20 AC 320 ms
139,872 KB
testcase_21 AC 324 ms
140,184 KB
testcase_22 AC 324 ms
139,856 KB
testcase_23 AC 317 ms
139,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Binary_Search_Small_Count(A,x,equal=False,sort=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort: A.sort()

    if len(A)==0 or A[0]>x or ((not equal) and A[0]==x):
        return 0

    L,R=0,len(A)
    while R-L>1:
        C=L+(R-L)//2
        if A[C]<x or (equal and A[C]==x): L=C
        else: R=C

    return L+1
#==================================================
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

inf=float("inf")
M=[[] for _ in range(N+1)]
for i in range(N+1):
    if i==0:
        M[0]=[A[0]]
    elif i==N:
        M[N]=[A[N-1]]
    else:
        M[i]=[A[i-1],A[i]]

for b in B:
    k=Binary_Search_Small_Count(A,b)
    M[k].append(b)

X=0
for k in range(N+1):
    if k==0 or k==N:
        X+=max(M[k])-min(M[k])
        continue

    if len(M[k])==2:
        continue

    M[k].sort()
    alpha=0
    for j in range(len(M[k])-1):
        alpha=max(alpha,M[k][j+1]-M[k][j])

    X+=(M[k][-1]-M[k][0])-alpha

print(X)
0