結果

問題 No.482 あなたの名は
ユーザー te-sh
提出日時 2017-12-11 16:28:11
言語 D
(dmd 2.109.1)
結果
RE  
実行時間 -
コード長 451 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 105,004 KB
実行使用メモリ 10,524 KB
最終ジャッジ日時 2024-06-12 22:59:50
合計ジャッジ時間 2,273 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 RE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], k = rd[1];
  auto d = readln.split.map!(to!int).map!"a-1".array;

  auto v = new bool[](n), t = 0, r = 0;
  foreach (i; 0..n) {
    if (v[i]) continue;
    auto j = i;
    while (!v[j]) {
      v[j] = true;
      ++r;
      j = d[j];
    }
    t += r-1;
    r = 0;
  }

  writeln(k >= t && (k-t)%2 == 0 ? "YES" : "NO");
}
0