結果
| 問題 |
No.2157 崖
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-09 23:05:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,594 ms / 6,000 ms |
| コード長 | 1,448 bytes |
| コンパイル時間 | 2,334 ms |
| コンパイル使用メモリ | 202,692 KB |
| 最終ジャッジ日時 | 2025-02-09 08:46:03 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;
using namespace atcoder;
using ll=long long;
using mint=modint998244353;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}
int n,m;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
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 ok=1<<30,ng=-1;
while(ok-ng>1){
int mid=(ok+ng)/2;
vector<int>dp(m,1);
rep(i,n-1){
int l=0,r=0,s=0;
bool f=true;
vector<int>dp2(m);
rep(j,m){
while(r<m&&d[i+1][j]>=d[i][r]){
if(dp[r]==1)s++;
r++;
}
while(l<m&&d[i+1][j]>d[i][l]+mid){
if(dp[l]==1)s--;
l++;
}
if(s>0)dp2[j]=1;
}
rep(j,m)swap(dp[j],dp2[j]);
}
bool flag=false;
rep(i,m)flag=flag||(dp[i]>0);
if(flag)ok=mid;
else ng=mid;
}
if(ok==1<<30)cout<<-1<<"\n";
else cout<<ok<<"\n";
}