結果

問題 No.482 あなたの名は
ユーザー beetbeet
提出日時 2017-02-10 22:28:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 492 bytes
コンパイル時間 1,638 ms
コンパイル使用メモリ 143,904 KB
実行使用メモリ 6,780 KB
最終ジャッジ日時 2023-08-28 15:39:06
合計ジャッジ時間 4,066 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 61 ms
6,528 KB
testcase_16 AC 60 ms
6,780 KB
testcase_17 AC 60 ms
6,572 KB
testcase_18 AC 60 ms
6,440 KB
testcase_19 AC 60 ms
6,588 KB
testcase_20 AC 60 ms
6,492 KB
testcase_21 AC 61 ms
6,532 KB
testcase_22 AC 60 ms
6,624 KB
testcase_23 AC 61 ms
6,492 KB
testcase_24 AC 61 ms
6,504 KB
testcase_25 AC 60 ms
6,624 KB
testcase_26 AC 61 ms
6,488 KB
testcase_27 AC 60 ms
6,416 KB
testcase_28 AC 60 ms
6,512 KB
testcase_29 AC 59 ms
6,420 KB
testcase_30 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
signed main(){
  int n,k;
  cin>>n>>k;
  int d[n];
  for(int i=0;i<n;i++) cin>>d[i];
  for(int i=0;i<n;i++) d[i]--;
  int r=0;
  int u[n];
  memset(u,0,sizeof(u));
  for(int i=0;i<n;i++){
    if(u[i]) continue;
    int t=0,c=i;
    while(!u[c]){
      u[c]=1;
      c=d[c];
      t++;
    }
    r+=t-1;
  }
  //cout<<r<<endl;
  if(r>k||(r-k)%2) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  return 0;
}
0