結果

問題 No.1767 BLUE to RED
ユーザー MasKoaTSMasKoaTS
提出日時 2022-01-06 16:39:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,113 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 148,772 KB
最終ジャッジ日時 2024-04-25 00:17:07
合計ジャッジ時間 8,857 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
86,144 KB
testcase_01 AC 136 ms
86,400 KB
testcase_02 AC 140 ms
86,528 KB
testcase_03 AC 140 ms
86,528 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools as iter
import collections as coll
import heapq as hq
import bisect as bis
from decimal import Decimal as dec
from copy import deepcopy as dcopy
import math
import sys
sys.setrecursionlimit(10**6)
def input():
    return sys.stdin.readline().rstrip()
def getN():
	return int(sys.stdin.readline())
def getNs():
	return map(int,sys.stdin.readline().split())
def getList():
	return list(map(int,sys.stdin.readline().split()))
def strinps(n):
	return [sys.stdin.readline().rstrip() for _ in range(n)]
pi = 3.141592653589793
mod = 10**9+7
MOD = 998244353
INF = math.inf
dx = [1,0,-1,0];	dy = [0,1,0,-1]


"""
Main Code
"""

n,m = getNs()
a = [i - 1 for i in getNs()]
b = [i - 1 for i in getNs()]
rb = max(a[-1],b[-1]) + 1
rg = [(-1,a[0]),(a[-1],rb)]
for i in range(n - 1):
	rg.append((a[i],a[i + 1]))

rg.sort()
ans = k = 0
for tp in rg:
	l,r = tp
	while(k < m and b[k] <= tp[1]):
		#print((tp,l,r,k,ans))
		if(b[k] <= l or b[k] >= r):
			k += 1
			continue
		if(l == -1 or (r - b[k] <= b[k] - l and r != rb)):
			ans += r - b[k]
			r = b[k]
		else:
			ans += b[k] - l
			l = b[k]
		k += 1
print(ans)
0