結果

問題 No.370 道路の掃除
ユーザー tookunn_1213tookunn_1213
提出日時 2016-05-14 00:12:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 524 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-22 17:37:40
合計ジャッジ時間 2,164 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,752 KB
testcase_01 AC 28 ms
10,752 KB
testcase_02 AC 29 ms
10,624 KB
testcase_03 AC 28 ms
10,624 KB
testcase_04 AC 27 ms
10,752 KB
testcase_05 AC 26 ms
10,624 KB
testcase_06 AC 26 ms
10,624 KB
testcase_07 AC 27 ms
10,624 KB
testcase_08 AC 27 ms
10,624 KB
testcase_09 AC 28 ms
10,496 KB
testcase_10 AC 28 ms
10,624 KB
testcase_11 AC 29 ms
10,752 KB
testcase_12 AC 28 ms
10,624 KB
testcase_13 AC 28 ms
10,624 KB
testcase_14 AC 29 ms
10,624 KB
testcase_15 AC 26 ms
10,624 KB
testcase_16 AC 28 ms
10,624 KB
testcase_17 AC 28 ms
10,496 KB
testcase_18 AC 28 ms
10,752 KB
testcase_19 AC 27 ms
10,624 KB
testcase_20 AC 61 ms
10,752 KB
testcase_21 AC 54 ms
10,752 KB
testcase_22 AC 27 ms
10,752 KB
testcase_23 AC 49 ms
10,624 KB
testcase_24 AC 29 ms
10,624 KB
testcase_25 AC 29 ms
10,496 KB
testcase_26 AC 48 ms
10,624 KB
testcase_27 AC 28 ms
10,752 KB
testcase_28 AC 34 ms
10,624 KB
testcase_29 AC 55 ms
10,752 KB
testcase_30 AC 72 ms
10,752 KB
testcase_31 AC 33 ms
10,624 KB
testcase_32 AC 28 ms
10,752 KB
testcase_33 AC 30 ms
10,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def getDis(d,N):
	now = 0
	pre = 0
	for j in range(len(d)):
		now += abs(abs(pre) - abs(d[j]))
		pre = d[j]
	return now
N,M = map(int,input().split())
D = [int(input())for i in range(M)]
if 0 not in D:
	D.append(0)
	M += 1
	N += 1
D.sort()
ans = 1000000000 + 7
for i in range(M - N + 1):
	if 0 not in D[i:i + N]:continue
	d = sorted(D[i:i + N])
	index0 = d.index(0)
	l = sorted(d[:index0],reverse=True)
	h = d[index0 + 1:]
	low = getDis(l,N)
	high = getDis(h,N)
	ans = min(ans,min(low,high) * 2 + max(low,high))
print (ans)
0