結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
19,072 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 TLE -
testcase_14 -- -
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/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;
    };

    ll ans=INF;
    rep(i,m){
        long long left=-1;
        long long right=2000000000;
        long long mid=(left+right)/2 +1;

        while(mid-left>1) {
            mid=(left+right)/2;
            if(check(mid)){
                right=mid;	
            } else {
                left=mid;
            }
        }
        chmin(ans,right);
    }

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

    return 0;                                                                                                      
}
0