結果
| 問題 |
No.3217 Shiki no Shiki
|
| コンテスト | |
| ユーザー |
ゼリトキ
|
| 提出日時 | 2025-08-01 21:28:07 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 729 bytes |
| コンパイル時間 | 2,795 ms |
| コンパイル使用メモリ | 276,072 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-08-01 21:28:13 |
| 合計ジャッジ時間 | 4,083 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
const long long mod=998244353;
const long long hmod=46216567629137;
int main(){
cin.tie(0)->sync_with_stdio(0);
cout.tie(0);
int N;
cin>>N;
int P[N+1];
for(int i=1;i<=N;i++) cin>>P[i];
int ans=0;
bool shikigami[N+1];
for(int i=1;i<=N;i++) shikigami[i]=0;
for(int i=1;i<=N;i++){
if(P[i]!=0) shikigami[P[i]]=1;
}
bool ok[N+1];
for(int i=1;i<=N;i++) ok[i]=0;
for(int i=1;i<=N;i++){
if(!shikigami[i]){
if(P[P[i]]!=0) ok[P[P[i]]]=1;
}
}
for(int i=1;i<=N;i++){
if(ok[i]) ans++;
}
cout<<ans<<"\n";
}
ゼリトキ