結果

問題 No.482 あなたの名は
ユーザー pinpin
提出日時 2017-02-11 00:11:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 849 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 51,836 KB
実行使用メモリ 5,252 KB
最終ジャッジ日時 2023-08-28 16:15:47
合計ジャッジ時間 2,778 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 59 ms
5,184 KB
testcase_16 AC 59 ms
5,120 KB
testcase_17 AC 60 ms
5,080 KB
testcase_18 AC 59 ms
5,092 KB
testcase_19 AC 59 ms
5,120 KB
testcase_20 AC 59 ms
5,196 KB
testcase_21 AC 59 ms
5,120 KB
testcase_22 AC 59 ms
5,128 KB
testcase_23 AC 59 ms
5,088 KB
testcase_24 AC 59 ms
5,192 KB
testcase_25 AC 59 ms
5,112 KB
testcase_26 AC 59 ms
5,068 KB
testcase_27 AC 59 ms
5,252 KB
testcase_28 AC 60 ms
5,176 KB
testcase_29 AC 57 ms
5,112 KB
testcase_30 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int main(void){
      long long int N ,K ;
     cin >> N >> K ;
     long long int a[N+1] ;
     bool used[N+1] ;
     
     for(int i=1;i<=N;i++){
          cin >> a[i] ;
          used[i] = false ;
     }
     
     
     int count = 0 ;
     for(int i=1;i<=N;i++){
          
          if(!used[i] && i != a[i]){
               used[i] = true ;
               
               int t = a[i] ;
               int s = a[t] ;
               used[t] = true ;
               
               while(t != i){
                    count++ ;
                    t = s ;
                    s = a[t] ;
                    used[t] = true ;
               }
          }
     }
   
     if(count<=K && (K-count)%2 == 0){
          cout << "YES" << endl ;
     }else{
          cout << "NO" << endl ;
          
     }

}
0