結果
問題 |
No.100 直列あみだくじ
|
ユーザー |
![]() |
提出日時 | 2014-12-11 23:34:05 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 764 bytes |
コンパイル時間 | 2,191 ms |
コンパイル使用メモリ | 74,900 KB |
実行使用メモリ | 41,560 KB |
最終ジャッジ日時 | 2024-06-11 20:39:48 |
合計ジャッジ時間 | 10,097 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 45 |
ソースコード
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"); } }