結果

問題 No.1245 ANDORゲーム(calc)
ユーザー 👑 obakyanobakyan
提出日時 2021-08-12 14:54:36
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,070 bytes
コンパイル時間 28 ms
コンパイル使用メモリ 6,684 KB
実行使用メモリ 35,712 KB
最終ジャッジ日時 2024-04-09 19:28:00
合計ジャッジ時間 6,571 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 7 ms
6,940 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 7 ms
6,944 KB
testcase_10 AC 6 ms
6,940 KB
testcase_11 AC 242 ms
35,712 KB
testcase_12 AC 233 ms
35,712 KB
testcase_13 AC 237 ms
35,712 KB
testcase_14 AC 236 ms
35,712 KB
testcase_15 AC 240 ms
35,712 KB
testcase_16 AC 236 ms
35,712 KB
testcase_17 AC 202 ms
35,712 KB
testcase_18 AC 199 ms
35,712 KB
testcase_19 AC 202 ms
35,712 KB
testcase_20 AC 210 ms
35,712 KB
testcase_21 AC 208 ms
35,712 KB
testcase_22 AC 201 ms
35,584 KB
testcase_23 AC 216 ms
35,712 KB
testcase_24 AC 217 ms
35,712 KB
testcase_25 AC 149 ms
35,712 KB
testcase_26 AC 160 ms
35,712 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local n, q = io.read("*n", "*n")
local t = {}
for i = 1, 30 do t[i] = {} end
for i = 1, n do
  local a = io.read("*n")
  for j = 1, 30 do
    t[j][i] = a % 2
    a = mfl(a / 2)
  end
end
io.read()
local s = io.read()
local tp = {}
for i = 1, n do
  tp[i] = s:byte(i) == 48
end

local score_0 = {}
local score_1 = {}

for i = 1, 30 do
  local s0, s1 = 0, 0
  local c0, c1 = 0, 1
  for j = 1, n do
    if tp[j] then -- AND
      if t[i][j] == 0 then
        if c0 == 1 then s0 = s0 + 1 end
        if c1 == 1 then s1 = s1 + 1 end
        c0, c1 = 0, 0
      end
    else -- OR
      if t[i][j] == 1 then
        if c0 == 0 then s0 = s0 + 1 end
        if c1 == 0 then s1 = s1 + 1 end
        c0, c1 = 1, 1
      end
    end
  end
  score_0[i], score_1[i] = s0, s1
end

for iq = 1, q do
  local a = io.read("*n")
  local mul = 1
  local ret = 0
  for i = 1, 30 do
    if a % 2 == 1 then
      ret = ret + score_1[i] * mul
    else
      ret = ret + score_0[i] * mul
    end
    a = mfl(a / 2)
    mul = mul * 2
  end
  print(ret)
end
0