結果

問題 No.482 あなたの名は
ユーザー k
提出日時 2020-07-03 03:01:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 595 bytes
コンパイル時間 1,895 ms
コンパイル使用メモリ 192,516 KB
最終ジャッジ日時 2025-01-11 13:59:28
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int d[200000+1];
bool vis[200000+1];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  long long k;
  cin >> n >> k;

  for (int i = 1; i <= n; i++)
    cin >> d[i];

  int ret = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i])
      continue;
    int c = 0;
    for (int j = i; !vis[j]; j = d[j]) {
      vis[j] = true;
      ++c;
    }
    ret += c-1;
  }

  if (k >= ret && (k - ret) % 2 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}
0