結果
| 問題 |
No.1245 ANDORゲーム(calc)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-12 14:54:36 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,070 bytes |
| コンパイル時間 | 102 ms |
| コンパイル使用メモリ | 6,820 KB |
| 実行使用メモリ | 35,840 KB |
| 最終ジャッジ日時 | 2024-10-01 19:38:32 |
| 合計ジャッジ時間 | 7,663 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 1 |
ソースコード
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