結果

問題 No.2157 崖
ユーザー tokumini_sstokumini_ss
提出日時 2022-12-09 22:01:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,320 bytes
コンパイル時間 2,697 ms
コンパイル使用メモリ 208,776 KB
実行使用メモリ 19,328 KB
最終ジャッジ日時 2024-04-22 22:09:37
合計ジャッジ時間 16,766 ms
ジャッジサーバーID
(参考情報)
judge4 / 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 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 906 ms
18,048 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 751 ms
15,872 KB
testcase_18 AC 740 ms
15,488 KB
testcase_19 WA -
testcase_20 AC 966 ms
19,328 KB
testcase_21 AC 966 ms
19,328 KB
testcase_22 AC 702 ms
14,976 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

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()) {
            cout << -1 << endl;
            return 0;
        }
        pre_value = *itr;
    }

    // 二分探索
    constexpr int64_t kInf = LLONG_MAX / 2;
    int64_t ok = kInf / 2, 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(*itr);
                }
            }
            st = new_st;
        }

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

    cout << ok << endl;
}
0