結果

問題 No.482 あなたの名は
ユーザー shinwisteriashinwisteria
提出日時 2017-03-30 18:12:57
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 692 bytes
コンパイル時間 3,110 ms
コンパイル使用メモリ 72,256 KB
実行使用メモリ 67,216 KB
最終ジャッジ日時 2023-09-21 08:45:22
合計ジャッジ時間 17,823 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,240 KB
testcase_01 AC 121 ms
56,204 KB
testcase_02 AC 122 ms
55,832 KB
testcase_03 AC 122 ms
56,176 KB
testcase_04 AC 121 ms
55,552 KB
testcase_05 AC 122 ms
55,800 KB
testcase_06 AC 120 ms
55,780 KB
testcase_07 AC 178 ms
56,252 KB
testcase_08 WA -
testcase_09 AC 139 ms
56,044 KB
testcase_10 AC 168 ms
55,696 KB
testcase_11 AC 177 ms
55,772 KB
testcase_12 AC 178 ms
56,028 KB
testcase_13 AC 173 ms
56,180 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 670 ms
63,044 KB
testcase_18 AC 695 ms
64,988 KB
testcase_19 AC 669 ms
64,448 KB
testcase_20 WA -
testcase_21 AC 696 ms
65,016 KB
testcase_22 WA -
testcase_23 AC 655 ms
64,780 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 680 ms
64,880 KB
testcase_27 AC 671 ms
64,820 KB
testcase_28 AC 661 ms
64,680 KB
testcase_29 AC 696 ms
67,016 KB
testcase_30 AC 124 ms
55,820 KB
権限があれば一括ダウンロードができます

ソースコード

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++){
			if(D[i] != 0){
				while(D[i] != i+1){
					//System.out.println("D[" + i + "] = " + D[i]);
					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