結果
| 問題 | No.2182 KODOKU Stone | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-01-07 18:37:29 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 105 ms / 2,000 ms | 
| コード長 | 1,698 bytes | 
| コンパイル時間 | 1,072 ms | 
| コンパイル使用メモリ | 89,788 KB | 
| 最終ジャッジ日時 | 2025-02-10 01:04:29 | 
| ジャッジサーバーID (参考情報) | judge1 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 37 | 
ソースコード
#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;
}
            
            
            
        