結果

問題 No.2157 崖
ユーザー nyyanyya
提出日時 2022-12-10 14:41:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,038 ms / 6,000 ms
コード長 1,633 bytes
コンパイル時間 4,407 ms
コンパイル使用メモリ 230,880 KB
実行使用メモリ 19,712 KB
最終ジャッジ日時 2024-04-22 23:50:26
合計ジャッジ時間 14,475 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 737 ms
13,824 KB
testcase_14 AC 920 ms
18,304 KB
testcase_15 AC 856 ms
13,824 KB
testcase_16 AC 852 ms
13,824 KB
testcase_17 AC 801 ms
16,128 KB
testcase_18 AC 761 ms
15,616 KB
testcase_19 AC 944 ms
16,512 KB
testcase_20 AC 1,038 ms
19,712 KB
testcase_21 AC 1,021 ms
19,584 KB
testcase_22 AC 744 ms
15,360 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
//using mint = modint;
using mint = modint998244353;
//using mint = modint1000000007;
using P = pair<int, int>;

const ll INF=1LL<<60, dx[]={0,1,0,-1},dy[]={1,0,-1,0};
template <typename T> inline bool chmin(T& a,const T&b) {if(a>b){a=b; return 1;} return 0;}
template <typename T> inline bool chmax(T& a,const T&b) {if(a<b){a=b; return 1;} return 0;}

int main(){

    int n,m;
    cin >> n >> m;

    vector<vector<ll>> d(n,vector<ll> (m));
    rep(i,n) {
        rep(j,m) cin >> d[i][j];
        sort(d[i].begin(),d[i].end()); 
    }

    auto check=[&](long long k) -> bool {
        vector<vector<bool>> dp(n, vector<bool>(m,false));
        rep(i,m) dp[0][i]=true;

        for(int i=1;i<n;i++) {
            int t=0;
            rep(j,m) {
                if(!dp[i-1][j]) continue;
                while(t<m && d[i-1][j]>d[i][t]) t++;
                while(t<m && d[i-1][j]+k >= d[i][t]) {
                    dp[i][t]=true;
                    t++;
                }
            } 
        }

        rep(i,m) {
            if(dp[n-1][i]) return true;
        }
        return false;
    };

    long long left=-1;
    long long right=2000000003;
    long long mid=(left+right)/2;

    while(right-left>1) {
        mid=(left+right)/2;
        if(check(mid)){
            right=mid;	
        } else {
            left=mid;
        }
        //cout << left << " " << mid << " " << right << endl;
    }

    cout << ((right>1000000000)?-1:right) << endl;

    return 0;
}
0