結果

問題 No.100 直列あみだくじ
ユーザー te-sh
提出日時 2017-04-25 11:26:13
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 548 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 112,360 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 18:51:34
合計ジャッジ時間 2,192 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void main()
{
  auto n = readln.chomp.to!size_t;
  auto ai = readln.split.to!(int[]).map!"a - 1".array;

  auto bi = new bool[](n);
  size_t[] ci;

  for (;;) {
    auto i = bi.countUntil!"!a".to!int;
    if (i == -1) break;

    auto j = i;
    int[] di;

    do {
      bi[j] = true;
      di ~= j;
      j = ai[j];
    } while (i != j);

    ci ~= di.length;
  }

  if (ci.sort().group.filter!"a[0] % 2 == 0".all!"a[1] % 2 == 0")
    writeln("Yes");
  else
    writeln("No");
}
0