結果

問題 No.2157 崖
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-04-03 23:34:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,206 bytes
コンパイル時間 2,855 ms
コンパイル使用メモリ 212,936 KB
実行使用メモリ 17,428 KB
最終ジャッジ日時 2024-04-03 23:35:11
合計ジャッジ時間 20,585 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace std;
using namespace atcoder;
using ll = long long;
int op(int a, int b) {return max(a, b);}
int e() {return 0;}
int main() {
	int N, M;cin >> N >> M;
	vector<vector<int>> D(N + 1, vector<int>(M + 1, 0));
	for (int i = 1;i <= N;i++) {
		for (int j = 1;j <= M;j++) cin >> D[i][j];
		sort(D[i].begin(), D[i].end());
	}
	int inf = (1e9) + 100;
	int ok = inf;
	int ng = -1;
	while (ok - ng > 1) {
		int X = (ok + ng) / 2;
		vector<int> d(M + 1, 1);d[0] = 0;
		segtree<int, op, e> dp(d);
		for (int i = 2;i <= N;i++) {
			vector<int> ndp(M + 1, 0);
			for (int j = 1;j <= M;j++) {
				int now = D[i][j];
				auto itr = lower_bound(D[i - 1].begin(), D[i - 1].end(), now - X);
				if (itr == D[i - 1].end()) continue;
				int L = itr - D[i - 1].begin();
				auto itr2 = upper_bound(D[i - 1].begin(), D[i - 1].end(), now);
				if (itr2 == D[i - 1].begin()) continue;
				itr2--;
				int R = itr2 - D[i - 1].begin();
				if (R < L) continue;
				ndp[j] = dp.prod(L, R + 1);
			}
			for (int j = 1;j <= M;j++) dp.set(j, ndp[j]);
		}
		if (dp.prod(0, M + 1) == 1) {
			ok = X;
		} else {
			ng = X;
		}
	}
	cout << (ok  == inf ? -1 : ok)<< endl;	
}
0