結果

問題 No.2157 崖
ユーザー nono00nono00
提出日時 2022-12-14 04:18:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,018 bytes
コンパイル時間 2,526 ms
コンパイル使用メモリ 202,232 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-04-25 10:12:18
合計ジャッジ時間 14,944 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 933 ms
18,048 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 788 ms
15,872 KB
testcase_18 AC 766 ms
15,488 KB
testcase_19 WA -
testcase_20 AC 1,030 ms
19,456 KB
testcase_21 AC 1,014 ms
19,328 KB
testcase_22 AC 744 ms
14,976 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define INF 1000000005

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> d(n, vector<int>(m));
    vector<vector<int>> nxt(n, vector<int>(m, -1));
    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());
    }

    for (int i = 0; i < n - 1; i++) {
        int j = 0;
        for (int l = 0; l < m; l++) {
            while (j < m && d[i][j] <= d[i + 1][l]) {
                nxt[i][j] = l;
                j++;
            }
        }
    }

    int ans = INF;
    for (int i = 0; i < m; i++) {
        int now = INF;
        int k = i;
        for (int j = 0; j < n - 1; j++) {
            if (nxt[j][k] == -1) {
                now = INF;
                break;
            }
            now = min(now, d[j + 1][nxt[j][k]] - d[j][k]);
            k = nxt[j][k];
        }
        ans = min(ans, now);
    }

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