結果

問題 No.3217 Shiki no Shiki
ユーザー asmin
提出日時 2025-08-01 21:54:33
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 834 bytes
コンパイル時間 4,251 ms
コンパイル使用メモリ 213,068 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-01 21:54:39
合計ジャッジ時間 5,319 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;



void solve(){
    int N; cin >> N;
    vector<bool> ok(N, true);
    vector<int> P(N);
    for(int i = 0; i < N; ++i){
        cin >> P[i];
        --P[i];
        if(P[i] == -1) continue;
        ok[P[i]] = false;
    }
    int cnt = 0;
    vector<bool> re(N, true);
    for(int i = 0; i < N; ++i){
        if(ok[i]){
            int c = i;
            c = P[c];
            if(c == -1) continue;
            c = P[c];
            if(c == -1) continue;
            if(re[c]){
                ++cnt;
                re[c] = false;
            }
        }
    }
    cout << cnt << "\n";
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(10) << fixed;


    int T;
    T = 1;
    //cin >> T;
    for(;T--;) solve();
}

0