結果

問題 No.1034 テスターのふっぴーさん
ユーザー 👑 obakyan
提出日時 2020-04-24 22:29:59
言語 Lua
(LuaJit 2.1.1734355927)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,494 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 6,688 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 03:11:38
合計ジャッジ時間 983 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

local mfl, mce = math.floor, math.ceil
local mab = math.abs
local mmi, mma = math.min, math.max
local function llprint(llnumber)
local str = tostring(llnumber):gsub("LL", "")
print(str)
end
local q = io.read("*n")
for iq = 1, q do
local n, i, j = io.read("*n", "*n", "*n")
n = n - 1
if n % 2 == 0 then
local center = mfl(n / 2)
local radius = mma(mab(i - center), mab(j - center))
local tot = (1LL + n) * (1LL + n)
if radius == 0 then
llprint(tot - 1LL)
else
local v = (radius * 2LL - 1LL) * (radius * 2LL - 1LL)
local line = radius * 2LL
if center - radius == i and center + radius ~= j then
-- top left
local diff_from_topleft = j - (center - radius)
local z = v + line * 4LL - diff_from_topleft
llprint(tot - z)
elseif center + radius == j and center + radius ~= i then
-- right top
local diff_from_righttop = i - (center - radius)
local z = v + line * 3LL - diff_from_righttop
llprint(tot - z)
elseif center + radius == i and center - radius ~= j then
-- bottom right
local diff_from_bottomright = center + radius - j
local z = v + line * 2LL - diff_from_bottomright
llprint(tot - z)
else
-- left bottom
local diff_from_leftbottom = center + radius - i
local z = v + line - diff_from_leftbottom
llprint(tot - z)
end
end
else -- n % 2 == 1
local hn = mfl((n + 1) / 2)
local radius = i < hn and hn - i or i - (hn - 1)
do
local tmp = j < hn and hn - j or j - (hn - 1)
radius = mma(radius, tmp)
end
local rl, rr = hn - radius, hn - 1 + radius
local tot = (1LL + n) * (1LL + n)
local v = (radius * 2LL - 2LL) * (radius * 2LL - 2LL)
local line = radius * 2LL - 1LL
if rl == i and rr ~= j then
-- top left
local diff_from_topleft = j - rl
local z = v + line * 4LL - diff_from_topleft
llprint(tot - z)
elseif rr == j and rr ~= i then
-- right top
local diff_from_righttop = i - rl
local z = v + line * 3LL - diff_from_righttop
llprint(tot - z)
elseif rr == i and rl ~= j then
-- bottom right
local diff_from_bottomright = rr - j
local z = v + line * 2LL - diff_from_bottomright
llprint(tot - z)
else
-- left bottom
local diff_from_leftbottom = rr - i
local z = v + line - diff_from_leftbottom
llprint(tot - z)
end
end
end
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0