結果

問題 No.43 野球の試合
ユーザー te-shte-sh
提出日時 2017-01-12 17:09:15
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 922 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 104,164 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 00:33:03
合計ジャッジ時間 1,574 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 43 ms
4,384 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void main()
{
  auto n = readln.chomp.to!size_t;
  auto gi = n.iota.map!(_ => readln.chomp.until("#")).join;

  auto ai = gi.enumerate.map!(g => g[1] == '-' ? g[0] : size_t.max).filter!(i => i < size_t.max).array;
  auto r = n;
  foreach (i; (1 << ai.length).iota) {
    auto bi = gi.dup;
    foreach (j, a; ai)
      bi[a] = bitTest(i, j) ? 'o' : 'x';
    r = min(r, calc(n, bi));
  }

  writeln(r);
}

auto calc(size_t n, dchar[] bi)
{
  auto wi = n.iota.map!(i => n.iota.map!(j => result(bi, i, j)).count(true)).array;
  auto w0 = wi[0];
  wi.sort!"a > b"();
  return wi.countUntil(w0) + 1;
}

bool result(dchar[] bi, size_t p1, size_t p2)
{
  if (p1 == p2)
    return false;
  else if (p1 > p2)
    return !result(bi, p2, p1);
  else
    return bi[(p2 - 1) * p2 / 2 + p1] == 'x';
}

bool bitTest(T)(T n, size_t i) { return (n & (1.to!T << i)) != 0; }
0