結果

問題 No.100 直列あみだくじ
ユーザー 37zigen
提出日時 2016-11-25 15:44:45
言語 Java
(openjdk 23)
結果
AC  
実行時間 175 ms / 5,000 ms
コード長 893 bytes
コンパイル時間 4,075 ms
コンパイル使用メモリ 80,384 KB
実行使用メモリ 41,736 KB
最終ジャッジ日時 2024-11-24 01:40:38
合計ジャッジ時間 13,126 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.*;

import javax.swing.plaf.synth.SynthScrollBarUI;

public class Q100 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; ++i) {
			a[i] = sc.nextInt() - 1;
		}
		boolean[] vis = new boolean[N];
		int[] loopSize = new int[N + 1];

		for (int i = 0; i < N; ++i) {
			if (!vis[i]) {
				int count = 1;
				int cur = i;
				vis[cur] = true;
				while (!vis[a[cur]]) {
					cur = a[cur];
					vis[cur] = true;
					++count;
				}
				++loopSize[count];
			}
		}
		for (int i = 1; i <= N; ++i) {
			if (i % 2 == 0 && loopSize[i] > 0) {
				if (loopSize[i] % 2 == 1) {
					System.out.println("No");
					return;
				}
			}
		}
		System.out.println("Yes");

	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0