結果

問題 No.2157 崖
ユーザー t98slidert98slider
提出日時 2022-12-09 21:44:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 821 ms / 6,000 ms
コード長 1,256 bytes
コンパイル時間 1,819 ms
コンパイル使用メモリ 171,904 KB
実行使用メモリ 11,216 KB
最終ジャッジ日時 2023-08-04 23:11:10
合計ジャッジ時間 9,690 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 604 ms
8,228 KB
testcase_14 AC 322 ms
10,548 KB
testcase_15 AC 821 ms
8,284 KB
testcase_16 AC 811 ms
8,320 KB
testcase_17 AC 273 ms
9,528 KB
testcase_18 AC 266 ms
8,972 KB
testcase_19 AC 800 ms
9,576 KB
testcase_20 AC 355 ms
11,216 KB
testcase_21 AC 354 ms
11,216 KB
testcase_22 AC 256 ms
8,776 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    vector<vector<int>> A(h, vector<int>(w));
    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            cin >> A[y][x];
        }
        sort(A[y].begin(), A[y].end());
    }
    auto f = [&](int lim){
        vector<int> dp(w + 1);
        dp[0] = 1;
        for(int y = 0; y + 1 < h; y++){
            vector<int> ndp(w + 1);
            for(int x = 0, l = 0, r = 0; x < w; x++){
                dp[x + 1] += dp[x];
                if(dp[x] == 0)continue;
                while(l < w && A[y + 1][l] < A[y][x])l++;
                while(r < w && A[y + 1][r] <= A[y][x] + lim)r++;
                ndp[l]++;
                ndp[r]--;
            }
            swap(dp, ndp);
        }
        for(int x = 0; x < w; x++){
            if(dp[x] >= 1)return true;
            dp[x + 1] += dp[x];
        }
        return false;
    };
    int ng = -1, ok = 1 << 30, mid;
    if(!f(ok)){
        cout << -1 << '\n';
        return 0;
    }
    while(ng + 1 < ok){
        mid = (ok + ng) / 2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << '\n';
}
0