結果

問題 No.2157 崖
ユーザー nono00nono00
提出日時 2022-12-14 05:29:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,244 bytes
コンパイル時間 2,201 ms
コンパイル使用メモリ 204,636 KB
実行使用メモリ 15,872 KB
最終ジャッジ日時 2024-04-25 11:04:11
合計ジャッジ時間 14,592 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
15,872 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 2,502 ms
8,448 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

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++;
                }
                int k = l;
                while (k < m && d[i][j] <= d[i + 1][k] && d[i + 1][k] <= d[i][j] + key) {
                    ndp[k] = true;
                    k++;
                }
            }
            swap(dp, 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