結果

問題 No.2157 崖
ユーザー t98slidert98slider
提出日時 2022-12-09 21:44:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 812 ms / 6,000 ms
コード長 1,256 bytes
コンパイル時間 1,731 ms
コンパイル使用メモリ 173,216 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-22 21:34:14
合計ジャッジ時間 8,699 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 581 ms
8,448 KB
testcase_14 AC 317 ms
10,752 KB
testcase_15 AC 793 ms
8,320 KB
testcase_16 AC 812 ms
8,320 KB
testcase_17 AC 270 ms
9,600 KB
testcase_18 AC 269 ms
9,344 KB
testcase_19 AC 774 ms
9,728 KB
testcase_20 AC 354 ms
11,520 KB
testcase_21 AC 348 ms
11,136 KB
testcase_22 AC 256 ms
9,088 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 3 ms
6,940 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