結果

問題 No.2157 崖
ユーザー shobonvipshobonvip
提出日時 2022-12-09 21:49:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 570 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 111,272 KB
最終ジャッジ日時 2024-04-22 21:41:57
合計ジャッジ時間 8,284 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
51,968 KB
testcase_01 AC 36 ms
52,352 KB
testcase_02 AC 36 ms
52,096 KB
testcase_03 AC 37 ms
51,840 KB
testcase_04 AC 37 ms
51,840 KB
testcase_05 AC 37 ms
52,224 KB
testcase_06 AC 36 ms
52,224 KB
testcase_07 AC 37 ms
52,096 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 35 ms
52,096 KB
testcase_11 WA -
testcase_12 AC 37 ms
52,224 KB
testcase_13 WA -
testcase_14 AC 578 ms
108,544 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 513 ms
103,908 KB
testcase_18 AC 499 ms
103,552 KB
testcase_19 WA -
testcase_20 AC 632 ms
111,272 KB
testcase_21 AC 643 ms
111,232 KB
testcase_22 AC 479 ms
102,784 KB
testcase_23 AC 36 ms
52,096 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int,input().split())
d = [list(map(int,input().split())) for i in range(n)]
for i in range(n):
	d[i].sort()
e = [[0] * m for i in range(n-1)]

for i in range(n-1):
	pivot = 0
	for j in range(m):
		while pivot < m and (pivot < 0 or d[i][pivot] <= d[i+1][j]):
			pivot += 1
		pivot -= 1
		if pivot >= 0:
			e[i][j] = pivot
		else:
			e[i][j] = -1

dp = [0] * m
for i in range(n-1):
	ndp = [10**18] * (m)
	for j in range(m):
		if e[i][j] >= 0:
			ndp[j] = dp[e[i][j]] + d[i+1][j] - d[i][e[i][j]]
	dp = ndp

if min(dp) >= 10**9:
	print(-1)
else:
	print(min(dp))
	
0