結果

問題 No.2157 崖
ユーザー roarisroaris
提出日時 2022-12-10 00:10:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,484 ms / 6,000 ms
コード長 1,279 bytes
コンパイル時間 1,966 ms
コンパイル使用メモリ 202,188 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-04-22 23:21:58
合計ジャッジ時間 16,111 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1,168 ms
11,392 KB
testcase_14 AC 1,269 ms
15,104 KB
testcase_15 AC 1,160 ms
12,416 KB
testcase_16 AC 1,191 ms
12,288 KB
testcase_17 AC 1,055 ms
14,208 KB
testcase_18 AC 1,024 ms
13,824 KB
testcase_19 AC 1,484 ms
12,672 KB
testcase_20 AC 1,368 ms
14,976 KB
testcase_21 AC 1,340 ms
15,232 KB
testcase_22 AC 996 ms
13,824 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 5 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
typedef long long ll;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    
    int N, M; cin >> N >> M;
    vector<int> D[N];
    rep(i, N) rep(j, M) {
        int d; cin >> d;
        D[i].pb(d);
    }
    rep(i, N) sort(D[i].begin(), D[i].end());
    
    int l = 0;
    int r = 1000000010;
    
    while (l<=r) {
        int m = (l+r)/2;
        
        bool dp[M];
        rep(i, M) dp[i] = true;
        
        for (int i=1; i<N; i++) {
            vector<int> acc = {0};
            rep(j, M) acc.pb(acc.back()+(dp[j] ? 1 : 0));
            
            bool ndp[M];
            rep(j, M) ndp[j] = false;
            int le = 0;
            int ri = 0;
            
            rep(j, M) {
                while (le<M && D[i][j]-D[i-1][le]>m) le++;
                while (ri<M && D[i][j]-D[i-1][ri]>=0) ri++;
                if (acc[ri]-acc[le]>0) ndp[j] = true;
            }
            rep(j, M) dp[j] = ndp[j];
        }
        
        bool ok = false;
        rep(i, M) if (dp[i]) ok = true;
        if (ok) r = m-1;
        else l = m+1;
    }
    
    int ans = l;
    if (ans>1000000010) cout << -1 << endl;
    else cout << ans << endl;
}
0