結果

問題 No.2157 崖
ユーザー take000take000
提出日時 2022-12-09 22:06:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 960 bytes
コンパイル時間 2,532 ms
コンパイル使用メモリ 203,212 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-22 22:13:55
合計ジャッジ時間 7,981 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 1 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 338 ms
10,624 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 288 ms
9,600 KB
testcase_18 AC 282 ms
9,216 KB
testcase_19 WA -
testcase_20 AC 371 ms
11,264 KB
testcase_21 AC 368 ms
11,264 KB
testcase_22 AC 266 ms
9,216 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace std;
const int INF = 2e9;

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int N, M;
    cin >> N >> M;
    vector D(N, vector<int>(M + 1, INF));
    rep(i, N) rep(j, M) cin >> D[i][j];
    rep(i, N) sort(D[i].begin(), D[i].end());

    auto f = [&](int i) -> int {
        if (i >= M) return INF;
        int mi = D[0][i];

        int cur = mi;
        for (int j = 1; j < N; ++j) {
            cur = *lower_bound(D[j].begin(), D[j].end(), cur);
        }

        if (cur == INF) return INF;
        return cur - mi;
    };

    ll l = 0, r = M;
    while (r - l > 2) {
        ll c1 = (l * 2 + r) / 3;
        ll c2 = (l + r * 2) / 3;
        if (f(c1) > f(c2))
            l = c1;
        else
            r = c2;
    }

    int ans = min({f(l), f(l + 1), f(l + 2)});
    if (ans == INF) ans = -1;
    cout << ans << "\n";

    return 0;
}
0