結果

問題 No.2157 崖
ユーザー 👑 rin204rin204
提出日時 2022-12-09 21:48:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 845 ms / 6,000 ms
コード長 1,238 bytes
コンパイル時間 2,782 ms
コンパイル使用メモリ 204,292 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-22 21:41:34
合計ジャッジ時間 12,438 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 640 ms
8,320 KB
testcase_14 AC 703 ms
10,624 KB
testcase_15 AC 789 ms
8,320 KB
testcase_16 AC 795 ms
8,448 KB
testcase_17 AC 598 ms
9,728 KB
testcase_18 AC 587 ms
9,216 KB
testcase_19 AC 845 ms
9,728 KB
testcase_20 AC 800 ms
11,520 KB
testcase_21 AC 791 ms
11,136 KB
testcase_22 AC 566 ms
9,088 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n'
const ll MOD = 998244353;

int main(){
    cin.tie(0)->sync_with_stdio(0);

    int n, m;
    cin >> n >> m;
    if(n == 1){
        cout << -1 << endl;
        return 0;
    }
    vector<vector<int>> D(n, vector<int>(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());
    }

    auto ok=[&](int x){
        vector<bool> dp(m, true);
        for(int i = 1; i < n; i++){
            vector<bool> ndp(m, false);
            int l = 0;
            for(int r = 0; r < m; r++){
                while((l < m) && ((!dp[l]) || (D[i][r] - D[i - 1][l] > x))){
                    l++;
                }
                if(l == m) break;
                int d = D[i][r] - D[i - 1][l];
                if(0 <= d && d <= x) ndp[r] = true;
            }
            swap(dp, ndp);
        }
        for(auto tf:dp){
            if(tf) return true;
        }
        return false;
    };

    int l = -1;
    int r = 1 << 30;
    while(r - l > 1){
        int mid = (l + r) / 2;
        if(ok(mid)) r = mid;
        else l = mid;
    }
    if(r == (1 << 30)) r = -1;
    cout << r << endl;
}
0