結果

問題 No.482 あなたの名は
ユーザー atkrymatkrym
提出日時 2017-02-19 13:50:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 692 ms / 2,000 ms
コード長 724 bytes
コンパイル時間 2,662 ms
コンパイル使用メモリ 73,540 KB
実行使用メモリ 66,904 KB
最終ジャッジ日時 2023-08-28 19:11:08
合計ジャッジ時間 17,185 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,908 KB
testcase_01 AC 119 ms
55,924 KB
testcase_02 AC 119 ms
55,668 KB
testcase_03 AC 119 ms
56,232 KB
testcase_04 AC 118 ms
55,768 KB
testcase_05 AC 119 ms
56,348 KB
testcase_06 AC 121 ms
55,656 KB
testcase_07 AC 176 ms
58,368 KB
testcase_08 AC 170 ms
58,060 KB
testcase_09 AC 134 ms
57,980 KB
testcase_10 AC 172 ms
57,924 KB
testcase_11 AC 176 ms
58,224 KB
testcase_12 AC 170 ms
57,768 KB
testcase_13 AC 173 ms
60,312 KB
testcase_14 AC 172 ms
58,232 KB
testcase_15 AC 692 ms
64,712 KB
testcase_16 AC 684 ms
64,428 KB
testcase_17 AC 642 ms
64,540 KB
testcase_18 AC 659 ms
64,556 KB
testcase_19 AC 655 ms
64,672 KB
testcase_20 AC 647 ms
64,528 KB
testcase_21 AC 643 ms
64,556 KB
testcase_22 AC 637 ms
64,888 KB
testcase_23 AC 644 ms
64,420 KB
testcase_24 AC 642 ms
64,940 KB
testcase_25 AC 646 ms
66,904 KB
testcase_26 AC 672 ms
64,860 KB
testcase_27 AC 665 ms
64,600 KB
testcase_28 AC 651 ms
65,076 KB
testcase_29 AC 685 ms
66,880 KB
testcase_30 AC 120 ms
55,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		long k = sc.nextLong();
		int[] l = new int[200010];
		boolean[] b = new boolean[200010];
		for (int i = 1;i <= n;i++) {
			l[i] = sc.nextInt();
		}

		int r = 0;
		for (int i = 1;i <= n;i++) {
			if (b[i]) continue;
			int s = i;
			int j = l[i];
			int c = 0;
			b[i] = true;
			while (true) {
				if (j==s) break;
				b[j] = true;
				j = l[j];
				c++;
			}
			r += c;
			b[i] = true;
		}

		if (r<=k) {
			if ((k-r)%2==0) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		} else {
			System.out.println("NO");
		}
	}
}
0