結果

問題 No.2157 崖
ユーザー keisuke6keisuke6
提出日時 2022-12-08 18:21:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,106 ms / 6,000 ms
コード長 1,157 bytes
コンパイル時間 2,411 ms
コンパイル使用メモリ 207,892 KB
実行使用メモリ 19,712 KB
最終ジャッジ日時 2024-04-22 16:12:22
合計ジャッジ時間 23,956 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1,643 ms
13,824 KB
testcase_14 AC 1,806 ms
18,432 KB
testcase_15 AC 1,617 ms
13,696 KB
testcase_16 AC 1,662 ms
13,824 KB
testcase_17 AC 1,554 ms
16,128 KB
testcase_18 AC 1,470 ms
15,744 KB
testcase_19 AC 2,067 ms
16,512 KB
testcase_20 AC 2,106 ms
19,712 KB
testcase_21 AC 1,965 ms
19,584 KB
testcase_22 AC 1,452 ms
15,232 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int N,M;
    cin>>N>>M;
    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());
    }
    int l = -1, r = 2e9;
    while(r-l > 1){
        int lim = (l+r)/2;
        bool ok = false;
        vector<vector<bool>> dp(N,vector<bool>(M,false));
        for(int i=0;i<M;i++) dp[0][i] = true;
        for(int i=1;i<N;i++){
            int ind_l = 0, ind_r = 0, count = 0;
            for(int j=0;j<M;j++){
                while(ind_l < M && D[i-1][ind_l] < D[i][j]-lim){
                    if(dp[i-1][ind_l]) count--;
                    ind_l++;
                }
                while(ind_r < M && D[i-1][ind_r] <= D[i][j]){
                    if(dp[i-1][ind_r]) count++;
                    ind_r++;
                }
                dp[i][j] = (count > 0);
            }
        }
        for(int i=0;i<M;i++)if(dp[N-1][i]) ok = true;
        if(ok) r = lim;
        else l = lim;
    }
    if(r == 2e9){
        cout<<-1<<endl;
        return 0;
    }
    cout<<r<<endl;
}
0