結果

問題 No.482 あなたの名は
ユーザー takeya_okinotakeya_okino
提出日時 2017-07-09 18:22:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 832 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 3,568 ms
コンパイル使用メモリ 78,876 KB
実行使用メモリ 54,252 KB
最終ジャッジ日時 2024-04-16 11:09:50
合計ジャッジ時間 18,859 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
40,268 KB
testcase_01 AC 127 ms
41,380 KB
testcase_02 AC 127 ms
41,276 KB
testcase_03 AC 131 ms
41,532 KB
testcase_04 AC 129 ms
41,220 KB
testcase_05 AC 134 ms
41,444 KB
testcase_06 AC 115 ms
40,380 KB
testcase_07 AC 182 ms
42,472 KB
testcase_08 AC 180 ms
41,980 KB
testcase_09 AC 143 ms
41,576 KB
testcase_10 AC 165 ms
41,872 KB
testcase_11 AC 187 ms
42,188 KB
testcase_12 AC 184 ms
42,312 KB
testcase_13 AC 175 ms
41,652 KB
testcase_14 AC 162 ms
41,744 KB
testcase_15 AC 709 ms
52,864 KB
testcase_16 AC 740 ms
53,096 KB
testcase_17 AC 760 ms
53,308 KB
testcase_18 AC 766 ms
52,896 KB
testcase_19 AC 771 ms
53,284 KB
testcase_20 AC 815 ms
52,860 KB
testcase_21 AC 800 ms
53,120 KB
testcase_22 AC 787 ms
53,048 KB
testcase_23 AC 832 ms
53,344 KB
testcase_24 AC 764 ms
52,896 KB
testcase_25 AC 779 ms
53,204 KB
testcase_26 AC 782 ms
52,396 KB
testcase_27 AC 689 ms
52,884 KB
testcase_28 AC 813 ms
52,664 KB
testcase_29 AC 737 ms
54,252 KB
testcase_30 AC 128 ms
41,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long K = sc.nextLong();
    int[] d = new int[N + 1];
    for(int i = 1; i < N + 1; i++) {
      d[i] = sc.nextInt();
    }
    long num = 0;
    for(int i = 1; i < N + 1; i++) {
      while(d[i] != i) {
        int temp = d[i];
        d[i] = d[d[i]];
        d[temp] = temp;
        num++;
      }
    }
    String ans = "NO";
    if(num <= K && (K - num) % 2 == 0) ans = "YES";
    System.out.println(ans);
  }
}
0