結果

問題 No.482 あなたの名は
ユーザー zaichu
提出日時 2017-02-16 22:32:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 881 ms
コンパイル使用メモリ 70,592 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-30 01:11:33
合計ジャッジ時間 2,496 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  long n,k;
  cin >> n >> k;
  vector<long> d(n);
  for(int i = 0; i < n; i++){
    cin >> d[i];
    d[i]--;
  }

  bool flag = true;

  for(int i = 0; i < n; i++){
    if(i == d[i]) continue;
    if(k < 0){
      flag = false;
      break;
    }
    swap(d[d[i]],d[i]);
    k--;
    i--;
  }
  if(flag and k % 2 != 0) flag = false;
  cout << (flag ? "YES" : "NO") << endl;

  return 0;
}
0