結果

問題 No.2288 Somen Sliders
ユーザー jianglyjiangly
提出日時 2023-04-28 23:44:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,599 bytes
コンパイル時間 2,238 ms
コンパイル使用メモリ 206,584 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-04-29 00:46:32
合計ジャッジ時間 5,742 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 44 ms
9,344 KB
testcase_11 RE -
testcase_12 AC 43 ms
8,832 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 45 ms
8,576 KB
testcase_16 AC 18 ms
5,376 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 23 ms
5,632 KB
testcase_20 AC 21 ms
5,760 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 15 ms
5,376 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 13 ms
5,376 KB
testcase_28 AC 11 ms
5,376 KB
testcase_29 AC 8 ms
5,376 KB
testcase_30 AC 18 ms
5,632 KB
testcase_31 AC 8 ms
5,376 KB
testcase_32 AC 8 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N, X, Y;
    std::cin >> N >> X >> Y;
    
    std::vector<std::vector<int>> a(X), b(Y);
    
    std::vector ida(N + 2, -1), idb(N + 2, -1), oa(N + 2, -1), ob(N + 2, -1);
    std::vector<int> pa(X), pb(X);
    
    for (int i = 0; i < X; i++) {
        int k;
        std::cin >> k;
        a[i].resize(k + 1);
        for (int j = 0; j <= k; j++) {
            std::cin >> a[i][j];
            ida[a[i][j]] = i;
            oa[a[i][j]] = j;
        }
        pa[i] = k;
    }
    
    for (int i = 0; i < Y; i++) {
        int k;
        std::cin >> k;
        b[i].resize(k + 1);
        for (int j = 0; j <= k; j++) {
            std::cin >> b[i][j];
            idb[b[i][j]] = i;
            ob[b[i][j]] = j;
        }
        pb[i] = k;
    }
    
    std::function<void(int)> extend = [&](int i) {
        while (pb[i]) {
            int x = b[i][pb[i]];
            if (ida[x] != -1 && pa[ida[x]] > oa[x]) {
                break;
            }
            pb[i]--;
        }
        
        if (!pb[i]) {
            return;
        }
        
        int x = b[i][pb[i]];
        int u = a[ida[x]][pa[ida[x]]];
        
        pa[ida[x]] = oa[x];
        
        if (u != N + 1 && idb[u] != -1) {
            extend(idb[u]);
        }
    };
    
    for (int i = 0; i < Y; i++) {
        extend(i);
    }
    
    int ans = 0;
    for (int i = 0; i < X; i++) {
        ans += pa[i];
    }
    
    std::cout << ans << "\n";
    
    return 0;
}
0