結果

問題 No.2157 崖
ユーザー shobonvipshobonvip
提出日時 2022-12-09 22:16:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,215 ms / 6,000 ms
コード長 837 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 114,580 KB
最終ジャッジ日時 2024-04-22 22:24:05
合計ジャッジ時間 33,645 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,352 KB
testcase_01 AC 41 ms
52,480 KB
testcase_02 AC 41 ms
52,096 KB
testcase_03 AC 47 ms
59,520 KB
testcase_04 AC 42 ms
52,224 KB
testcase_05 AC 50 ms
60,416 KB
testcase_06 AC 43 ms
52,480 KB
testcase_07 AC 59 ms
61,440 KB
testcase_08 AC 42 ms
52,736 KB
testcase_09 AC 44 ms
53,248 KB
testcase_10 AC 43 ms
52,224 KB
testcase_11 AC 58 ms
62,336 KB
testcase_12 AC 42 ms
51,968 KB
testcase_13 AC 3,448 ms
101,752 KB
testcase_14 AC 3,339 ms
111,408 KB
testcase_15 AC 3,035 ms
101,496 KB
testcase_16 AC 3,245 ms
101,316 KB
testcase_17 AC 2,054 ms
106,220 KB
testcase_18 AC 2,791 ms
105,452 KB
testcase_19 AC 4,215 ms
107,520 KB
testcase_20 AC 2,506 ms
114,360 KB
testcase_21 AC 3,120 ms
114,580 KB
testcase_22 AC 2,336 ms
104,984 KB
testcase_23 AC 42 ms
52,096 KB
testcase_24 AC 110 ms
77,044 KB
権限があれば一括ダウンロードができます

ソースコード

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 d[i][pivot] <= d[i+1][j]:
			pivot += 1
		e[i][j] = pivot

suki = 10 ** 9 + 2
kirai = -1
while suki - kirai > 1:
	targ = (suki + kirai) // 2
	dp = [1] * m
	for i in range(n-1):
		pfix = [0] * (m+1)
		for j in range(m):
			pfix[j+1] = pfix[j] + dp[j]
		ndp = [0] * m
		pivot = 0
		f = [0] * m
		for j in range(m):
			while pivot < m and d[i][pivot] < d[i+1][j] - targ:
				pivot += 1
			f[j] = pivot
		for j in range(m):
			v = pfix[e[i][j]] - pfix[f[j]]
			if v >= 1: ndp[j] = 1
		dp = ndp
		#print(*dp)
	if sum(dp) == 0:
		kirai = targ
	else:
		suki = targ

if kirai >= 10 ** 9:
	print(-1)
else:
	print(suki)
0