結果

問題 No.2157 崖
ユーザー shobonvipshobonvip
提出日時 2022-12-09 21:49:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 570 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 111,224 KB
最終ジャッジ日時 2024-04-22 21:43:32
合計ジャッジ時間 7,549 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
53,160 KB
testcase_01 AC 31 ms
53,420 KB
testcase_02 AC 33 ms
53,852 KB
testcase_03 AC 35 ms
52,248 KB
testcase_04 AC 33 ms
53,116 KB
testcase_05 AC 31 ms
53,076 KB
testcase_06 AC 31 ms
52,948 KB
testcase_07 AC 31 ms
52,768 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 32 ms
52,924 KB
testcase_11 WA -
testcase_12 AC 33 ms
52,208 KB
testcase_13 WA -
testcase_14 AC 529 ms
108,368 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 462 ms
103,948 KB
testcase_18 AC 472 ms
103,316 KB
testcase_19 WA -
testcase_20 AC 579 ms
110,932 KB
testcase_21 AC 594 ms
111,224 KB
testcase_22 AC 443 ms
102,588 KB
testcase_23 AC 33 ms
52,620 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**14:
	print(-1)
else:
	print(min(dp))
0