結果

問題 No.3223 K-XOR Increasing Sequence
ユーザー jiangxinyang
提出日時 2025-08-01 21:31:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 821 bytes
コンパイル時間 706 ms
コンパイル使用メモリ 79,576 KB
実行使用メモリ 30,920 KB
最終ジャッジ日時 2025-08-01 21:32:25
合計ジャッジ時間 20,677 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2 RE * 1
other WA * 29 RE * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

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

    int n;
    cin >> n;
    vector<int> fa(n + 1);
    vector<vector<int>> vec(n + 1);
    vector<bool> chk1(n + 1, 1), chk2(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> fa[i];
        if (!fa[i]) continue;
        vec[fa[i]].push_back(i);
        chk1[fa[i]] = 0;
    }
    for (int i = 1; i <= n; i++) {
        for (auto j : vec[i]) {
            if (chk1[j]) {
                chk2[i] = 1;
                break;
            }
        }
    }
    int tot = 0;
    for (int i = 1; i <= n; i++) {
        for (auto j : vec[i]) {
            if (chk2[j]) {
                tot++;
                break;
            }
        }
    }
    cout << tot << endl;
    return 0;
}
0