結果

問題 No.482 あなたの名は
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2017-02-10 23:30:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,497 bytes
コンパイル時間 692 ms
コンパイル使用メモリ 88,216 KB
実行使用メモリ 9,664 KB
最終ジャッジ日時 2023-08-28 16:15:08
合計ジャッジ時間 3,125 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,420 KB
testcase_01 AC 4 ms
7,444 KB
testcase_02 AC 3 ms
7,524 KB
testcase_03 AC 3 ms
7,504 KB
testcase_04 AC 4 ms
7,420 KB
testcase_05 AC 4 ms
7,456 KB
testcase_06 AC 3 ms
7,532 KB
testcase_07 AC 4 ms
7,420 KB
testcase_08 AC 3 ms
7,424 KB
testcase_09 AC 4 ms
7,452 KB
testcase_10 AC 4 ms
7,452 KB
testcase_11 AC 3 ms
7,412 KB
testcase_12 AC 4 ms
7,456 KB
testcase_13 AC 3 ms
7,456 KB
testcase_14 AC 4 ms
7,512 KB
testcase_15 AC 64 ms
9,500 KB
testcase_16 AC 64 ms
9,528 KB
testcase_17 AC 64 ms
9,504 KB
testcase_18 AC 64 ms
9,608 KB
testcase_19 AC 64 ms
9,604 KB
testcase_20 AC 64 ms
9,484 KB
testcase_21 AC 63 ms
9,612 KB
testcase_22 AC 64 ms
9,664 KB
testcase_23 AC 63 ms
9,604 KB
testcase_24 AC 63 ms
9,556 KB
testcase_25 AC 65 ms
9,532 KB
testcase_26 AC 63 ms
9,620 KB
testcase_27 AC 63 ms
9,448 KB
testcase_28 AC 64 ms
9,556 KB
testcase_29 AC 62 ms
9,536 KB
testcase_30 AC 3 ms
7,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll d[200010];
ll dd[200010];
ll ddd[200010];

int main() {
  ll n,k;
  cin>>n>>k;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    a--;
    v.pb(a);
  }
  rep(i,0,v.sz){
    d[v[i]] = i; 
  }
  clr(dd,0);
  int index = 1;
  rep(i,0,n){
    if(dd[i]!=0)continue;
    if(d[i]==i){
      dd[i]=index;
      index++;
      continue;;
    }
    ll a = i;
    while(1){
      dd[a] = index;
      a = d[a];
      if(a==i){
        index++;
        break;
      }
    }
  }
  clr(ddd,0);
  rep(i,0,n){
    ddd[dd[i]]++;
  }
  ll ans = 0;
  rep(i,0,n+1){
    ans += max(0LL,ddd[i]-1);
  }
  if(ans>k){
    cout << "NO" << endl;
  }
  else if((k-ans)%2==1){
    cout << "NO" << endl;
  }
  else{
    cout << "YES" << endl;
  }
  return 0;
}
0