結果

問題 No.2288 Somen Sliders
ユーザー 👑 hitonanodehitonanode
提出日時 2023-04-28 22:57:49
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,848 bytes
コンパイル時間 1,087 ms
コンパイル使用メモリ 97,952 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2024-04-29 00:18:05
合計ジャッジ時間 3,059 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 42 ms
8,960 KB
testcase_11 AC 20 ms
6,940 KB
testcase_12 AC 41 ms
8,576 KB
testcase_13 AC 47 ms
8,832 KB
testcase_14 AC 48 ms
8,960 KB
testcase_15 AC 40 ms
8,192 KB
testcase_16 AC 17 ms
6,940 KB
testcase_17 AC 14 ms
6,940 KB
testcase_18 AC 21 ms
6,940 KB
testcase_19 AC 22 ms
6,940 KB
testcase_20 AC 21 ms
6,944 KB
testcase_21 AC 22 ms
6,944 KB
testcase_22 AC 48 ms
10,112 KB
testcase_23 AC 37 ms
8,704 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 14 ms
6,944 KB
testcase_26 AC 5 ms
6,944 KB
testcase_27 AC 13 ms
6,940 KB
testcase_28 AC 11 ms
6,944 KB
testcase_29 AC 8 ms
6,940 KB
testcase_30 AC 18 ms
6,940 KB
testcase_31 AC 8 ms
6,940 KB
testcase_32 AC 8 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <numeric>
#include <vector>
using namespace std;


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

    int N, X, Y;
    cin >> N >> X >> Y;

    vector<vector<int>> P(X), Q(Y);

    for (auto &vec : P) {
        int len;
        cin >> len;
        vec.resize(len + 1);
        for (auto &x: vec) cin >> x, --x;
        vec.pop_back();
        vec.erase(vec.begin());
    }

    for (auto &vec : Q) {
        int len;
        cin >> len;
        vec.resize(len + 1);
        for (auto &x : vec) cin >> x, --x;
        vec.pop_back();
        vec.erase(vec.begin());
    }

    vector<int> belong_to(N, -1), pos(N, -1);
    for (int x = 0; x < X; ++x) {
        const auto &seq = P.at(x);
        for (int d = 0; d < int(seq.size()); ++d) {
            belong_to.at(seq.at(d)) = x;
            pos.at(seq.at(d)) = d;
        }
    }

    vector<int> next_red(N, -1);
    vector<int> pending;

    for (const auto &seq : Q) {
        int pr = -1;
        for (int x : seq) {
            if (belong_to.at(x) >= 0) next_red.at(x) = pr, pr = x;
        }
        if (pr >= 0) pending.push_back(pr);
    }

    vector<int> heights;
    for (const auto &v : P) heights.push_back(v.size());
    
    while (pending.size()) {
        int now = pending.back();
        pending.pop_back();

        if (const int l = belong_to.at(now), p = pos.at(now); heights.at(l) > p) {
            if (heights.at(l) < int(P.at(l).size())) {
                int old = P.at(l).at(heights.at(l));
                int pr = next_red.at(old);
                if (pr >= 0) pending.push_back(pr);
            }
            heights.at(l) = p;
        } else {
            int pr = next_red.at(now);
            if (pr >= 0) pending.push_back(pr);
        }
    }
    cout << accumulate(heights.cbegin(), heights.cend(), X) << endl;
}
0