結果
問題 |
No.3217 Shiki no Shiki
|
ユーザー |
![]() |
提出日時 | 2025-08-24 12:07:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 878 bytes |
コンパイル時間 | 3,445 ms |
コンパイル使用メモリ | 253,560 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-08-24 12:07:13 |
合計ジャッジ時間 | 5,739 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; #define ll long long #define rep(i,a,b) for(int i=(a);i<(b);i++) #define repl(i,a,b) for(ll i=(a);i<(b);i++) #define all(a) (a).begin(),(a).end() template <typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;} return false;} template <typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;} return false;} int main(){ int n; cin >> n; vector<bool> ch(n,false); vector<int> p(n); rep(i,0,n){ cin >> p[i]; p[i]--; if(p[i] != -1) ch[p[i]]=true; } vector<bool> flag(n,false); int ans=0; rep(i,0,n){ if(ch[i]) continue; int now=i; int num=0; while(p[now] != -1 && num<=2){ now=p[now]; num++; if(num == 2){ if(flag[now]) break; ans++; flag[now]=true; } } } cout << ans << endl; }