結果

問題 No.2288 Somen Sliders
ユーザー jianglyjiangly
提出日時 2023-04-28 23:46:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,599 bytes
コンパイル時間 3,586 ms
コンパイル使用メモリ 204,404 KB
実行使用メモリ 10,476 KB
最終ジャッジ日時 2023-08-11 08:13:02
合計ジャッジ時間 4,672 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 43 ms
8,960 KB
testcase_11 AC 21 ms
6,156 KB
testcase_12 AC 42 ms
8,448 KB
testcase_13 AC 50 ms
8,840 KB
testcase_14 AC 50 ms
8,924 KB
testcase_15 AC 40 ms
8,264 KB
testcase_16 AC 17 ms
5,104 KB
testcase_17 AC 13 ms
5,084 KB
testcase_18 AC 19 ms
5,444 KB
testcase_19 AC 21 ms
5,508 KB
testcase_20 AC 21 ms
5,332 KB
testcase_21 AC 21 ms
5,368 KB
testcase_22 AC 50 ms
10,476 KB
testcase_23 AC 37 ms
8,804 KB
testcase_24 AC 3 ms
4,384 KB
testcase_25 AC 13 ms
4,632 KB
testcase_26 AC 5 ms
4,380 KB
testcase_27 AC 13 ms
5,092 KB
testcase_28 AC 11 ms
4,844 KB
testcase_29 AC 8 ms
4,744 KB
testcase_30 AC 18 ms
5,092 KB
testcase_31 AC 9 ms
4,828 KB
testcase_32 AC 8 ms
4,888 KB
testcase_33 AC 2 ms
4,384 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(Y);
    
    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