結果

問題 No.100 直列あみだくじ
ユーザー ぴろず
提出日時 2014-12-11 23:38:04
言語 Java
(openjdk 23)
結果
AC  
実行時間 137 ms / 5,000 ms
コード長 764 bytes
コンパイル時間 2,489 ms
コンパイル使用メモリ 74,928 KB
実行使用メモリ 41,552 KB
最終ジャッジ日時 2024-11-24 01:34:43
合計ジャッジ時間 9,746 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

package no100;

import java.util.Scanner;

public class Main {

	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();
		}
		boolean[] used = new boolean[n];
		int[] count = new int[51];
		for(int i=0;i<n;i++) {
			if (used[i]) {
				continue;
			}
			int length = 0;
			int now = i;
			while(true) {
				if (used[now]) {
					break;
				}
				used[now] = true;
				length++;
				now = a[now] - 1;
			}
			count[length]++;
		}
		for(int i=2;i<=50;i++) {
			if (i % 2 == 0) {
				if (count[i] % 2 == 1) {
					System.out.println("No");
					return;
				}
			}
		}
		System.out.println("Yes");
	}

}
0