結果

問題 No.2157 崖
ユーザー ぷらぷら
提出日時 2022-12-09 21:50:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,841 ms / 6,000 ms
コード長 1,378 bytes
コンパイル時間 2,453 ms
コンパイル使用メモリ 204,180 KB
実行使用メモリ 20,004 KB
最終ジャッジ日時 2024-04-22 21:45:47
合計ジャッジ時間 19,041 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1,028 ms
15,944 KB
testcase_14 AC 1,490 ms
19,456 KB
testcase_15 AC 1,734 ms
15,464 KB
testcase_16 AC 1,700 ms
15,256 KB
testcase_17 AC 1,227 ms
17,620 KB
testcase_18 AC 1,263 ms
17,420 KB
testcase_19 AC 1,435 ms
17,604 KB
testcase_20 AC 1,841 ms
20,004 KB
testcase_21 AC 1,780 ms
20,000 KB
testcase_22 AC 1,278 ms
17,336 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 4 ms
11,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int dp[1515][1515];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    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 = 1001001001;
    while(l+1 < r) {
        int mid = (l+r)/2;
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < M; j++) {
                dp[i][j] = 0;
                if(i == 0) dp[i][j] = 1;
            }
        }
        for(int i = 0; i+1 < N; i++) {
            for(int j = 0; j < M; j++) {
                if(dp[i][j] != 0) {
                    int it1 = lower_bound(D[i+1].begin(),D[i+1].end(),D[i][j])-D[i+1].begin();
                    int it2 = upper_bound(D[i+1].begin(),D[i+1].end(),D[i][j]+mid)-D[i+1].begin();
                    dp[i+1][it1]++;
                    dp[i+1][it2]--;
                }
            }
            for(int j = 0; j < M; j++) {
                dp[i+1][j+1] += dp[i+1][j];
            }
        }
        bool f = false;
        for(int i = 0; i < M; i++) {
            if(dp[N-1][i]) {
                f = true;
            }
        }
        if(f) r = mid;
        else l = mid;
    }
    cout << ((r == 1001001001)?-1:r) << endl;
}
0