結果

問題 No.2157 崖
ユーザー nono00nono00
提出日時 2022-12-14 05:39:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,091 ms / 6,000 ms
コード長 1,217 bytes
コンパイル時間 2,601 ms
コンパイル使用メモリ 204,568 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-25 11:11:39
合計ジャッジ時間 14,341 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 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 792 ms
8,448 KB
testcase_14 AC 973 ms
10,752 KB
testcase_15 AC 893 ms
8,448 KB
testcase_16 AC 906 ms
8,448 KB
testcase_17 AC 839 ms
9,472 KB
testcase_18 AC 811 ms
9,600 KB
testcase_19 AC 1,049 ms
9,728 KB
testcase_20 AC 1,091 ms
11,264 KB
testcase_21 AC 1,061 ms
11,264 KB
testcase_22 AC 837 ms
9,344 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;

#define INF 1000000001

int 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 ng = -1, ok = INF;

    while (ok - ng > 1) {
        int key = (ok + ng) / 2;
        vector<bool> dp(m, true);

        for (int i = 0; i < n - 1; i++) {
            vector<bool> ndp(m, false);
            int l = 0;
            for (int j = 0; j < m; j++) {
                if (!dp[j]) continue;
                while (l < m && d[i + 1][l] < d[i][j]) {
                    l++;
                }
                while (l < m && d[i][j] <= d[i + 1][l] && d[i + 1][l] <= d[i][j] + key) {
                    ndp[l] = true;
                    l++;
                }
            }
            dp.swap(ndp);
        }

        bool flag = false;

        for (int i = 0; i < m; i++) {
            if (dp[i]) {
                flag = true;
                break;
            }
        }

        if (flag) ok = key;
        else ng = key;
    }

    cout << (ok == INF ? -1 : ok) << endl;
}
0