結果
問題 |
No.3217 Shiki no Shiki
|
ユーザー |
|
提出日時 | 2025-08-01 21:39:01 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 638 bytes |
コンパイル時間 | 3,108 ms |
コンパイル使用メモリ | 279,068 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-08-01 21:39:05 |
合計ジャッジ時間 | 4,315 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> p(n), in(n, 0); for (int &x : p) cin >> x; for (int x : p) { if (x > 0) in[x - 1]++; } vector<bool> ans(n, false); for (int i = 0; i < n; i++) { if (in[i] == 0) { int res = i; for (int j = 0; j < 2; j++) { if (res >= 0) res = p[res] - 1; } if (res >= 0) ans[res] = true; } } cout << count(ans.begin(), ans.end(), true) << "\n"; return 0; }