結果

問題 No.482 あなたの名は
コンテスト
ユーザー atkrym
提出日時 2017-02-19 13:50:44
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 493 ms / 2,000 ms
コード長 724 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,930 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 58,532 KB
最終ジャッジ日時 2026-06-03 21:23:56
合計ジャッジ時間 10,867 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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