結果

問題 No.482 あなたの名は
ユーザー shinwisteria
提出日時 2017-03-30 18:08:39
言語 Java
(openjdk 23)
結果
RE  
実行時間 -
コード長 606 bytes
コンパイル時間 3,405 ms
コンパイル使用メモリ 74,892 KB
実行使用メモリ 56,872 KB
最終ジャッジ日時 2024-07-07 03:03:19
合計ジャッジ時間 18,117 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 RE * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class YourName {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int rest = N;
		long K = s.nextLong();
		int[] D = new int[N];
		for(int i = 0;i < N;i++){
			D[i] = s.nextInt();
			if(i+1 == D[i]){
				D[i] = 0;
				rest--;
			}
		}
		s.close();
		for(int i = 0;i < rest;i++){
			while(D[i] != i+1){
				int k = D[D[i]-1];
				D[D[i]-1] = 0;
				rest--;
				D[i] = k;
				K--;
			}
			if(K < 0){
				break;
			}
		}
		if(K % 2 == 0){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}

}
0