結果

問題 No.2157 崖
ユーザー kotatsugamekotatsugame
提出日時 2022-12-09 21:33:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,587 ms / 6,000 ms
コード長 695 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 71,580 KB
実行使用メモリ 14,664 KB
最終ジャッジ日時 2024-04-22 20:58:50
合計ジャッジ時間 15,889 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 1,019 ms
12,108 KB
testcase_14 AC 1,449 ms
14,408 KB
testcase_15 AC 1,007 ms
12,744 KB
testcase_16 AC 1,015 ms
12,492 KB
testcase_17 AC 1,242 ms
13,640 KB
testcase_18 AC 1,193 ms
13,516 KB
testcase_19 AC 1,294 ms
12,876 KB
testcase_20 AC 1,571 ms
14,280 KB
testcase_21 AC 1,587 ms
14,664 KB
testcase_22 AC 1,153 ms
13,644 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 4 ms
14,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N,M;
int D[1500][1500];
bool dp[1500][1500];
int main()
{
	cin>>N>>M;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<M;j++)cin>>D[i][j];
		sort(D[i],D[i]+M);
	}
	int L=-1,R=(int)1e9+1;
	while(R-L>1)
	{
		int mid=(L+R)/2;
		for(int j=0;j<M;j++)dp[0][j]=true;
		for(int i=1;i<N;i++)
		{
			int p=-1;
			int nj=0;
			for(int j=0;j<M;j++)
			{
				while(nj<M&&D[i-1][nj]<=D[i][j])
				{
					if(dp[i-1][nj])p=D[i-1][nj];
					nj++;
				}
				dp[i][j]=p!=-1&&D[i][j]-p<=mid;
			}
		}
		bool fn=false;
		for(int j=0;j<M;j++)if(dp[N-1][j])
		{
			fn=true;
			break;
		}
		if(fn)R=mid;
		else L=mid;
	}
	if(R==(int)1e9+1)R=-1;
	cout<<R<<endl;
}
0