結果

問題 No.1467 Selling Cars
ユーザー QCFiumQCFium
提出日時 2021-03-12 11:57:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,134 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 23,808 KB
最終ジャッジ日時 2024-04-21 22:24:41
合計ジャッジ時間 10,972 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections

def fast_one(a, b, k) :
	n = len(a)
	m = len(b)
	
	used = [collections.deque() for i in range(n + 1)]
	
	closest = 0
	for i in range(m) :
		while closest + 1 < n and abs(b[i] - a[closest]) >= abs(b[i] - a[closest + 1]) : closest += 1
		if len(used[closest]) == k :
			r = closest
			l = closest
			while l and len(used[l - 1]) == k : l -= 1
			while r + 1 < n and len(used[r + 1]) == k : r += 1
			r += 1
			used[r].append(i)
			
			shift_delta = 0
			for j in range(l, r + 1) : shift_delta += abs(a[j - 1] - b[used[j][0]]) - abs(a[j] - b[used[j][0]])
			if shift_delta < 0 :
				for j in range(l, r + 1) :
					used[j - 1].append(used[j][0])
					used[j].popleft()
		else : used[closest].append(i)
	
	res = 0
	for i in range(n) :
		for j in used[i] : res += abs(a[i] - b[j])
	
	return res

def fast(a, b) :
	a.sort()
	b.sort()
	a = [-1000000000000000000] + a + [1000000000000000000]
	
	res = []
	for i in range(1, m + 1) : res.append(fast_one(a, b, i))
	return res

m, n = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

res = fast(b, a)
for i in res : print(i)
0