結果

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

ソースコード

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++){
          int m = 0 ;
          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 ;
                    count += m++ ;
               }
          }
     }
   
     if(count<=K && (K-count)%2 == 0){
          cout << "YES" << endl ;
     }else{
          cout << "NO" << endl ;
          
     }

}
0