結果

問題 No.2157 崖
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-05 16:01:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,876 ms / 6,000 ms
コード長 1,110 bytes
コンパイル時間 1,394 ms
コンパイル使用メモリ 118,884 KB
実行使用メモリ 19,408 KB
最終ジャッジ日時 2023-08-14 23:20:50
合計ジャッジ時間 29,851 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1,851 ms
13,640 KB
testcase_14 AC 2,384 ms
17,856 KB
testcase_15 AC 2,668 ms
13,288 KB
testcase_16 AC 2,610 ms
13,576 KB
testcase_17 AC 2,005 ms
15,692 KB
testcase_18 AC 2,011 ms
15,336 KB
testcase_19 AC 2,518 ms
16,300 KB
testcase_20 AC 2,876 ms
19,140 KB
testcase_21 AC 2,789 ms
19,408 KB
testcase_22 AC 1,974 ms
14,836 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

ll N, M;
vector<vector<ll>> D;

bool solve(ll c){
    ll n;
    vector<ll> q;
    for (int i=0; i<M; i++) q.push_back(D[0][i]);
    for (int i=1; i<N; i++){
        vector<ll> p;
        for (int j=0; j<M; j++){
            n = upper_bound(q.begin(), q.end(), D[i][j]) - lower_bound(q.begin(), q.end(), D[i][j]-c);
            if (n) p.push_back(D[i][j]);
        }
        swap(p, q);
    }
    return q.size() > 0;
}

int main(){

    cin >> N >> M;
    if (N == 1){
        cout << 0 << endl;
        return 0;
    }
    D.resize(N,  vector<ll>(M));
    for (int i=0; i<N; i++){
        for (int j=0; j<M; j++) cin >> D[i][j];
        sort(D[i].begin(), D[i].end());
    }

    ll l=-1, r=1e9, c;
    while(r-l>1){
        c = (l+r)/2;
        if (solve(c)) r=c;
        else l=c;
    }

    cout << (r == 1e9 ? -1 : r) << endl;

    return 0;
}
0