結果

問題 No.43 野球の試合
ユーザー 👑 obakyanobakyan
提出日時 2019-05-06 00:05:29
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 65 ms / 5,000 ms
コード長 1,590 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 13:40:55
合計ジャッジ時間 1,113 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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)
0