結果

問題 No.3217 Shiki no Shiki
ユーザー ジュ・ビオレ・グレイス
提出日時 2025-08-01 21:34:04
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 418 bytes
コンパイル時間 1,434 ms
コンパイル使用メモリ 87,592 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-08-01 21:34:07
合計ジャッジ時間 2,115 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.algorithm, std.array, std.conv, std.typecons;

alias Set = bool[3 * 10^^5];

void main() {
	readln;
	auto P = readln.split.to!(ulong[]);
	P = [0UL] ~ P;
	auto N = P.length-1;
	
	auto set = new bool[N+1];
	foreach (p; P) {
		set[p] = true;
	}
	
	auto ans = new bool[N+1];
	foreach (i; 1 .. N+1) if (!set[i]){
		if (P[i] != 0 && P[P[i]] != 0) ans[P[P[i]]] = true;
	}
	
	writeln(ans.count(true));
}
0