結果

問題 No.482 あなたの名は
ユーザー YamaKasa
提出日時 2018-09-23 15:50:23
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 756 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 77,280 KB
実行使用メモリ 55,212 KB
最終ジャッジ日時 2024-09-14 01:56:08
合計ジャッジ時間 15,352 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 WA * 4 RE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		long K = scan.nextInt();
		int[]D1 = new int[N + 1];
		int[]D2 = new int[N + 1];
		for(int i = 0; i < N; i++) {
			//D[i] = scan.nextInt();
			int t = scan.nextInt();
			D1[i + 1] = t;
			D2[t] = i + 1;
		}
		scan.close();

		long cnt = 0;
		for(int i = 1; i <= N; i++) {
			if(D1[i] != i) {
				int t1 = D1[i];
				int t2 = D2[i];
				D1[i] = i;
				D2[i] = i;
				D1[t2] = t1;
				D2[t1] = t1;
				cnt++;
			}
		}

		if(cnt > K) {
			System.out.println("NO");
		}else {
			long t = K - cnt;
			if(t % 2 == 0) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
		}
	}
}
0