結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_14 AC 2,828 ms
18,048 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2,546 ms
16,000 KB
testcase_18 AC 2,400 ms
15,488 KB
testcase_19 WA -
testcase_20 AC 3,811 ms
19,456 KB
testcase_21 AC 3,538 ms
19,328 KB
testcase_22 AC 2,263 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++;
            }
        }
    }

    // (ng, ok) = [-1, INF]
    // ok == INFなら,ans = -1

    /*
        key = 3;

        l = r = 5;

        l += 3; r ++ 3;
        d[0][0] = 5のとき,次の値は[5, 8]
        li = lower_bound(b, e, 5)
        ri = upper_bound(b, e, 5 + key)

        if distance(l, r) == 0: break;
        l = *li
        r = *(--ri)
    */

    int ng = -1, ok = INF;

    while (ok - ng > 1) {
        int key = (ok + ng) / 2;
        bool flag1 = false;

        for (int j = 0; j < m; j++) {
            int l = d[0][j], r = d[0][j];
            bool flag2 = true;

            for (int i = 1; i < n; i++) {
                r += key;
                auto li = lower_bound(d[i].begin(), d[i].end(), l);
                auto ri = upper_bound(d[i].begin(), d[i].end(), r);
                if (distance(li, ri) == 0) {
                    flag2 = false;
                    break;
                }
                l = *li;
                r = *(--ri);
            }

            if (flag2) {
                flag1 = true;
                break;
            }
        }

        if (flag1) {
            ok = key;
        } else {
            ng = key;
        }
    }

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