結果

問題 No.482 あなたの名は
ユーザー tonyu0
提出日時 2019-10-25 19:17:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 547 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 64,484 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-21 16:12:01
合計ジャッジ時間 2,556 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
using ll = long long;
ll N, K, D[200020];
bool used[200020];

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false); 
  cin >> N >> K;
  for(int i = 1; i <= N; ++i) cin >> D[i];

  ll ans = 0;
  for(int i = 1; i <= N; ++i) {
    if(!used[i] && i != D[i]) {
      used[i] = true;
      int pos = D[i];
      while(pos != i) {
        used[pos] = true;
        pos = D[pos];
        ++ans;
      }
    }
  }
  if((ans % 2) == (K % 2)) cout << "YES";
  else cout << "NO";
  cout << endl;

  return 0;
}
0