結果
| 問題 | No.43 野球の試合 | 
| コンテスト | |
| ユーザー | 👑 | 
| 提出日時 | 2019-05-06 00:05:29 | 
| 言語 | Lua (LuaJit 2.1.1734355927) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 63 ms / 5,000 ms | 
| コード長 | 1,590 bytes | 
| コンパイル時間 | 402 ms | 
| コンパイル使用メモリ | 7,072 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-26 06:49:21 | 
| 合計ジャッジ時間 | 1,352 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
ソースコード
local ior = io.input()
local n = ior:read("*n", "*l")
local tot = math.floor(n * (n - 1) / 2)
local t = {}
for i = 1, tot do t[i] = 0 end
local str, sstr = "", ""
local function getidx(row, col)
  local ret = 0
  for i = 1, row - 1 do
    ret = ret + n - i
  end
  ret = ret + (col - row)
  return ret
end
for i = 1, n do
  str = ior:read()
  for j = i + 1, n do
    sstr = str:sub(j, j)
    local idx = getidx(i, j)
    if(sstr == "o") then t[idx] = 1 elseif(sstr == "x") then t[idx] = -1 end
  end
end
local allpat = 1
for i = 1, tot do
  allpat = allpat * 2
end
local highrank = n
for i_tot = 0, allpat - 1 do
  local tmpi = i_tot
  local subt = {}
  for j = 1, tot do
    table.insert(subt, (tmpi % 2) * 2 - 1)
    tmpi = math.floor(tmpi / 2)
  end
  local isok = true
  for j = 1, tot do
    if(t[j] ~= 0 and t[j] ~= subt[j]) then
      isok = false
      break
    end
  end
  if(isok) then
    local kati = {}
    for i = 1, n do kati[i] = 0 end
    for i = 1, n - 1 do
      for j = i + 1, n do
        local idx = getidx(i, j)
        if(subt[idx] == 1) then
          kati[i] = kati[i] + 1
        else
          kati[j] = kati[j] + 1
        end
      end
    end
    local num_per_kati = {}
    for i = 1, n do
      num_per_kati[i] = false
    end
    for i = 1, n do
      num_per_kati[kati[i] + 1] = true
    end
    local rank = 1
    for i = n, 1, -1 do
      if(num_per_kati[i]) then
        if(kati[1] + 1 == i) then
          break
        else
          rank = rank + 1
        end
      end
    end
    highrank = math.min(highrank, rank)
  end
end
print(highrank)
            
            
            
        