結果

問題 No.100 直列あみだくじ
ユーザー 37zigen37zigen
提出日時 2016-11-25 15:44:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 893 bytes
コンパイル時間 3,755 ms
コンパイル使用メモリ 77,204 KB
実行使用メモリ 56,096 KB
最終ジャッジ日時 2023-08-15 17:41:14
合計ジャッジ時間 11,653 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,668 KB
testcase_01 AC 129 ms
55,588 KB
testcase_02 AC 126 ms
55,580 KB
testcase_03 AC 131 ms
55,912 KB
testcase_04 AC 128 ms
55,696 KB
testcase_05 AC 123 ms
55,736 KB
testcase_06 AC 123 ms
55,956 KB
testcase_07 AC 124 ms
55,700 KB
testcase_08 AC 125 ms
55,748 KB
testcase_09 AC 125 ms
55,388 KB
testcase_10 AC 126 ms
55,640 KB
testcase_11 AC 125 ms
55,672 KB
testcase_12 AC 124 ms
55,932 KB
testcase_13 AC 125 ms
55,588 KB
testcase_14 AC 124 ms
55,768 KB
testcase_15 AC 124 ms
55,544 KB
testcase_16 AC 125 ms
55,704 KB
testcase_17 AC 124 ms
55,632 KB
testcase_18 AC 124 ms
55,576 KB
testcase_19 AC 124 ms
55,688 KB
testcase_20 AC 125 ms
55,552 KB
testcase_21 AC 124 ms
56,000 KB
testcase_22 AC 125 ms
55,844 KB
testcase_23 AC 126 ms
55,544 KB
testcase_24 AC 125 ms
55,828 KB
testcase_25 AC 124 ms
55,700 KB
testcase_26 AC 123 ms
56,020 KB
testcase_27 AC 125 ms
55,852 KB
testcase_28 AC 124 ms
55,540 KB
testcase_29 AC 126 ms
55,748 KB
testcase_30 AC 132 ms
55,780 KB
testcase_31 AC 126 ms
55,580 KB
testcase_32 AC 131 ms
55,896 KB
testcase_33 AC 125 ms
55,564 KB
testcase_34 AC 124 ms
56,096 KB
testcase_35 AC 130 ms
55,760 KB
testcase_36 AC 131 ms
55,564 KB
testcase_37 AC 134 ms
55,336 KB
testcase_38 AC 129 ms
55,780 KB
testcase_39 AC 134 ms
55,456 KB
testcase_40 AC 131 ms
55,680 KB
testcase_41 AC 130 ms
56,052 KB
testcase_42 AC 132 ms
55,888 KB
testcase_43 AC 131 ms
55,720 KB
testcase_44 AC 129 ms
55,552 KB
testcase_45 AC 131 ms
55,496 KB
testcase_46 AC 131 ms
55,740 KB
testcase_47 AC 133 ms
55,768 KB
権限があれば一括ダウンロードができます

ソースコード

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