結果

問題 No.2182 KODOKU Stone
ユーザー suisensuisen
提出日時 2023-01-07 18:37:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,698 bytes
コンパイル時間 888 ms
コンパイル使用メモリ 93,864 KB
実行使用メモリ 8,876 KB
最終ジャッジ日時 2023-08-21 08:42:43
合計ジャッジ時間 5,957 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 48 ms
8,856 KB
testcase_12 AC 73 ms
8,876 KB
testcase_13 AC 15 ms
4,380 KB
testcase_14 AC 17 ms
4,384 KB
testcase_15 AC 70 ms
8,860 KB
testcase_16 AC 46 ms
8,872 KB
testcase_17 AC 19 ms
4,376 KB
testcase_18 AC 44 ms
7,864 KB
testcase_19 AC 37 ms
5,120 KB
testcase_20 AC 45 ms
7,024 KB
testcase_21 AC 18 ms
4,376 KB
testcase_22 AC 16 ms
4,376 KB
testcase_23 AC 31 ms
4,808 KB
testcase_24 AC 23 ms
4,380 KB
testcase_25 AC 13 ms
4,376 KB
testcase_26 AC 15 ms
4,376 KB
testcase_27 AC 15 ms
4,380 KB
testcase_28 AC 37 ms
6,500 KB
testcase_29 AC 44 ms
7,484 KB
testcase_30 AC 47 ms
8,028 KB
testcase_31 AC 38 ms
6,480 KB
testcase_32 AC 39 ms
6,216 KB
testcase_33 AC 40 ms
7,224 KB
testcase_34 AC 20 ms
4,380 KB
testcase_35 AC 43 ms
7,220 KB
testcase_36 AC 12 ms
4,376 KB
testcase_37 AC 45 ms
8,084 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <vector>

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (auto &e : a) std::cin >> e;

    std::vector<std::vector<int>> b(n);
    for (int i = 0; i < n; ++i) {
        int k;
        std::cin >> k;
        b[i].resize(k);
        for (int j = 0; j < k; ++j) {
            std::cin >> b[i][j];
        }
    }

    auto check = [&](int x) -> bool {
        std::map<int, int> p, q;
        for (int i = 0; i < n; ++i) {
            std::array<int, 2> cnt{ 0, 0 };
            for (int v : b[i]) {
                ++cnt[v >= x];
            }
            ++(cnt[0] ? p : q)[cnt[1]];
        }
        int maxp = -1;
        for (int i = n - 1; i >= 0; --i) {
            if (p.lower_bound(a[i]) != p.end() or q.lower_bound(a[i]) != q.end()) {
                return true;
            }
            if (maxp >= a[i] and not q.empty()) return true;
            if (auto itp = p.find(a[i] - 1); itp != p.end()) {
                maxp = std::max(maxp, itp->first);
                if (--(itp->second) == 0) {
                    p.erase(itp);
                }
            } else if (auto itq = q.begin(); itq != q.end()) {
                if (--(itq->second) == 0) {
                    q.erase(itq);
                }
                if (i == 0) return true;
            } else {
                return false;
            }
        }
        return false;
    };

    int l = 0, r = 1000000010;
    while (r - l > 1) {
        int x = (l + r) >> 1;
        (check(x) ? l : r) = x;
    }
    std::cout << l << std::endl;
}
0