結果

問題 No.2157 崖
ユーザー tokumini_sstokumini_ss
提出日時 2022-12-09 22:10:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4,428 ms / 6,000 ms
コード長 1,385 bytes
コンパイル時間 2,859 ms
コンパイル使用メモリ 207,684 KB
実行使用メモリ 19,840 KB
最終ジャッジ日時 2024-04-22 22:20:33
合計ジャッジ時間 40,038 ms
ジャッジサーバーID
(参考情報)
judge2 / 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 1 ms
5,376 KB
testcase_04 AC 3 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 1 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,460 ms
13,952 KB
testcase_14 AC 3,582 ms
18,432 KB
testcase_15 AC 3,801 ms
13,952 KB
testcase_16 AC 3,752 ms
14,080 KB
testcase_17 AC 2,997 ms
16,256 KB
testcase_18 AC 3,003 ms
15,744 KB
testcase_19 AC 3,380 ms
16,512 KB
testcase_20 AC 4,428 ms
19,840 KB
testcase_21 AC 4,315 ms
19,712 KB
testcase_22 AC 2,991 ms
15,360 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int64_t N, M;
    cin >> N >> M;

    vector<vector<int64_t>> D(N, vector<int64_t>(M));
    for (int64_t i = 0; i < N; i++) {
        for (int64_t j = 0; j < M; j++) {
            cin >> D[i][j];
        }
        sort(D[i].begin(), D[i].end());
    }

    // // -1であるかどうか判定
    // int64_t pre_value = 0;
    // for (int64_t i = 0; i < N; i++) {
    //     auto itr = lower_bound(D[i].begin(), D[i].end(), pre_value);
    //     if (itr == D[i].end()) {
    //         assert(false);
    //         cout << -1 << endl;
    //         return 0;
    //     }
    //     pre_value = *itr;
    // }

    // 二分探索
    const int64_t kInf = 2e9;
    int64_t ok = kInf, ng = -1;
    while (ok - ng != 1) {
        const int64_t mid = (ok + ng) / 2;
        set<int64_t> st;
        for (int64_t j = 0; j < M; j++) {
            st.insert(D[0][j]);
        }

        for (int64_t i = 1; i < N; i++) {
            set<int64_t> new_st;
            for (int64_t j = 0; j < M; j++) {
                auto itr = st.lower_bound(D[i][j] - mid);
                if (itr != st.end() && *itr <= D[i][j]) {
                    new_st.insert(D[i][j]);
                }
            }
            st = new_st;
        }

        (st.empty() ? ng = mid : ok = mid);
    }

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