結果

問題 No.100 直列あみだくじ
ユーザー 37zigen37zigen
提出日時 2016-11-25 15:44:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 893 bytes
コンパイル時間 3,788 ms
コンパイル使用メモリ 86,808 KB
実行使用メモリ 41,772 KB
最終ジャッジ日時 2024-05-03 04:35:04
合計ジャッジ時間 9,697 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
41,372 KB
testcase_01 AC 102 ms
41,524 KB
testcase_02 AC 116 ms
41,308 KB
testcase_03 AC 121 ms
41,508 KB
testcase_04 AC 120 ms
41,304 KB
testcase_05 AC 103 ms
41,048 KB
testcase_06 AC 113 ms
40,828 KB
testcase_07 AC 103 ms
41,028 KB
testcase_08 AC 102 ms
41,112 KB
testcase_09 AC 101 ms
39,948 KB
testcase_10 AC 117 ms
41,116 KB
testcase_11 AC 121 ms
40,112 KB
testcase_12 AC 127 ms
40,832 KB
testcase_13 AC 126 ms
41,380 KB
testcase_14 AC 126 ms
41,692 KB
testcase_15 AC 115 ms
41,372 KB
testcase_16 AC 111 ms
39,932 KB
testcase_17 AC 119 ms
41,020 KB
testcase_18 AC 107 ms
41,772 KB
testcase_19 AC 115 ms
40,352 KB
testcase_20 AC 96 ms
41,528 KB
testcase_21 AC 102 ms
41,396 KB
testcase_22 AC 110 ms
41,548 KB
testcase_23 AC 113 ms
40,960 KB
testcase_24 AC 103 ms
41,200 KB
testcase_25 AC 118 ms
41,224 KB
testcase_26 AC 122 ms
41,304 KB
testcase_27 AC 108 ms
41,380 KB
testcase_28 AC 121 ms
41,420 KB
testcase_29 AC 102 ms
41,128 KB
testcase_30 AC 120 ms
41,540 KB
testcase_31 AC 115 ms
40,904 KB
testcase_32 AC 108 ms
41,332 KB
testcase_33 AC 104 ms
41,264 KB
testcase_34 AC 121 ms
41,416 KB
testcase_35 AC 119 ms
41,212 KB
testcase_36 AC 110 ms
41,032 KB
testcase_37 AC 121 ms
41,436 KB
testcase_38 AC 100 ms
41,584 KB
testcase_39 AC 117 ms
41,352 KB
testcase_40 AC 105 ms
41,512 KB
testcase_41 AC 117 ms
41,320 KB
testcase_42 AC 112 ms
41,772 KB
testcase_43 AC 117 ms
41,452 KB
testcase_44 AC 117 ms
41,428 KB
testcase_45 AC 107 ms
41,320 KB
testcase_46 AC 115 ms
41,512 KB
testcase_47 AC 113 ms
41,308 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