結果

問題 No.482 あなたの名は
ユーザー pin
提出日時 2017-02-11 00:11:40
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 849 bytes
コンパイル時間 707 ms
コンパイル使用メモリ 54,488 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-29 20:23:32
合計ジャッジ時間 2,670 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

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