結果

問題 No.2157 崖
コンテスト
ユーザー 沙耶花
提出日時 2022-12-09 21:36:42
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,141 ms / 6,000 ms
コード長 1,053 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,118 ms
コンパイル使用メモリ 278,868 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2026-06-28 19:49:04
合計ジャッジ時間 14,391 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 2000000000000000001

long long op(long long a,long long b){
	return min(a,b);
}

long long e(){
	return Inf64;
}

int main(){
	
	int n,m;
	cin>>n>>m;
	
	vector a(n,vector<long long> (m));
	rep(i,n){
		rep(j,m)scanf("%lld",&a[i][j]);
		sort(a[i].begin(),a[i].end());
	}
	
	long long ok = Inf32,ng = -1;
	while(ok-ng>1){
		int mid = (ok+ng)/2;
		vector<bool> f(m,true);
		for(int i=1;i<n;i++){
			vector<bool> nf(m,false);
			int l = 0,r = 0,s = 0;
			rep(j,m){
				while(r!=m && a[i-1][r]<=a[i][j]){
					if(f[r])s++;
					r++;
				}
				while(l!=m && a[i-1][l]<=a[i][j] && a[i][j]-a[i-1][l]>mid){
					if(f[l])s--;
					l++;
				}
				nf[j] = (s>0);
			}
			swap(f,nf);
		}
		bool F = false;
		rep(i,m){
			if(f[i])F = true;
		}
		if(F)ok = mid;
		else ng = mid;
		
	}
	if(ok==Inf32)ok = -1;
	cout<<ok<<endl;
	
	return 0;
}
0