結果
| 問題 | No.43 野球の試合 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-08-31 14:00:49 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 87 ms / 5,000 ms | 
| コード長 | 1,329 bytes | 
| コンパイル時間 | 1,023 ms | 
| コンパイル使用メモリ | 130,928 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-12 03:59:39 | 
| 合計ジャッジ時間 | 1,875 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
ソースコード
import std.algorithm, std.array, std.container, std.range;
import std.numeric, std.math, std.bigint, std.bitmanip, std.random;
import std.string, std.conv, std.stdio, std.typecons;
enum Game { NA, NotYet, Win, Lose }
alias Tuple!(int, int) pos;
void main()
{
  auto n = readln.chomp.to!int;
  auto tij = iota(n).map!((i) {
    return readln.chomp.map!((c) {
      switch (c) {
      case '#': return Game.NA;
      case '-': return Game.NotYet;
      case 'o': return Game.Win;
      case 'x': return Game.Lose;
      default: assert(0);
      }
    }).array;
  }).array;
  pos[] ai;
  foreach (i; 0..n)
    foreach (j; i + 1..n)
      if (tij[i][j] == Game.NotYet)
        ai ~= pos(i, j);
  if (!ai.empty) {
    auto min = n;
    foreach (i; 0..2 ^^ ai.length) {
      auto b = bitsSet(i);
      auto uij = tij.dup.map!(dup).array;
      foreach (j, a; ai) {
        uij[a[0]][a[1]] = b.canFind(j) ? Game.Win : Game.Lose;
        uij[a[1]][a[0]] = b.canFind(j) ? Game.Lose : Game.Win;
      }
      auto r = calcRank(uij);
      if (r < min) min = r;
    }
    writeln(min);
  } else {
    writeln(calcRank(tij));
  }
}
int calcRank(Game[][] tij)
{
  auto wi = tij.map!(a => a.count!(b => b == Game.Win)).array;
  auto w = wi.front;
  auto x = wi.sort!("a > b").uniq.array;
  return x.until(w).array.length.to!int + 1;
}
            
            
            
        