結果

問題 No.2157 崖
ユーザー norikamenorikame
提出日時 2022-12-09 22:59:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,302 ms / 6,000 ms
コード長 1,228 bytes
コンパイル時間 4,126 ms
コンパイル使用メモリ 257,648 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-22 22:54:07
合計ジャッジ時間 19,778 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,820 KB
testcase_02 AC 2 ms
6,948 KB
testcase_03 AC 1 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,948 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 1,567 ms
8,704 KB
testcase_14 AC 930 ms
10,624 KB
testcase_15 AC 2,302 ms
8,320 KB
testcase_16 AC 2,222 ms
8,448 KB
testcase_17 AC 779 ms
9,472 KB
testcase_18 AC 761 ms
9,344 KB
testcase_19 AC 2,186 ms
9,728 KB
testcase_20 AC 1,017 ms
11,264 KB
testcase_21 AC 1,019 ms
11,392 KB
testcase_22 AC 738 ms
9,088 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

const int INF = (int)(1.5e9);

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> d(n, vector<int>(m));
	rep(i, n) {
		rep(j, m) cin >> d[i][j];
		sort(all(d[i]));
	}
	int lval = -1, rval = INF;
	while (rval-lval > 1) {
		int cval = lval + (rval-lval) / 2;
		vector<int> dist(m+1), ndist;
		rep(i, m) dist[i] = 1;
		rep(i, n-1) {
			ndist.assign(m+1, 0);
			rep(j, m) if (dist[j] > 0) {
				int di = d[i][j], ndi = di + cval;
				int li = lower_bound(all(d[i+1]), di) - d[i+1].begin(), ri = upper_bound(all(d[i+1]), ndi) - d[i+1].begin();
				ndist[li]++, ndist[ri]--;
			}
			rep(j, m) ndist[j+1] += ndist[j];
			swap(ndist, dist);
		}
		int vcnt = 0;
		rep(i, m) if (dist[i] > 0) ++vcnt;
		if (vcnt > 0) rval = cval;
		else lval = cval;
	}
	if (rval == INF) cout << -1 << endl;
	else cout << rval << endl;
	return 0;
}
0