結果

問題 No.2157 崖
ユーザー 👑 rin204rin204
提出日時 2022-12-09 21:48:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 772 ms / 6,000 ms
コード長 1,238 bytes
コンパイル時間 2,792 ms
コンパイル使用メモリ 209,000 KB
実行使用メモリ 11,208 KB
最終ジャッジ日時 2023-08-04 23:17:57
合計ジャッジ時間 11,709 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 569 ms
8,324 KB
testcase_14 AC 647 ms
10,436 KB
testcase_15 AC 722 ms
8,300 KB
testcase_16 AC 731 ms
8,360 KB
testcase_17 AC 548 ms
9,360 KB
testcase_18 AC 543 ms
9,108 KB
testcase_19 AC 772 ms
9,700 KB
testcase_20 AC 741 ms
11,208 KB
testcase_21 AC 731 ms
11,208 KB
testcase_22 AC 523 ms
8,836 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,380 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