結果
| 問題 |
No.1650 Moving Coins
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2021-08-20 21:50:30 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 200 ms / 2,000 ms |
| コード長 | 1,072 bytes |
| コンパイル時間 | 147 ms |
| コンパイル使用メモリ | 5,120 KB |
| 実行使用メモリ | 21,120 KB |
| 最終ジャッジ日時 | 2024-10-14 03:19:12 |
| 合計ジャッジ時間 | 6,369 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
local n = io.read("*n")
local a, b = {}, {}
for i = 1, n do
a[i] = io.read("*n")
end
for i = 1, n do
b[i] = io.read("*n")
end
local c = {}
local tp = {}
local csum = 0
for i = 1, n do
if a[i] < b[i] then
tp[i] = "R"
c[i] = b[i] - a[i]
elseif b[i] < a[i] then
tp[i] = "L"
c[i] = a[i] - b[i]
else
tp[i] = ""
c[i] = 0
end
csum = csum + c[i]
end
print(csum)
local curpos = 1
while curpos <= n do
if tp[curpos] == "R" then
local spos = curpos
local tpos = curpos + 1
while tpos <= n and tp[tpos] == "R" do
tpos = tpos + 1
end
for i = tpos - 1, spos, -1 do
io.write(string.rep(i .. " R\n", b[i] - a[i]))
end
curpos = tpos
else
curpos = curpos + 1
end
end
curpos = n
while 1 <= curpos do
if tp[curpos] == "L" then
local spos = curpos
local tpos = curpos - 1
while 1 <= tpos and tp[tpos] == "L" do
tpos = tpos - 1
end
for i = tpos + 1, spos do
io.write(string.rep(i .. " L\n", a[i] - b[i]))
end
curpos = tpos
else
curpos = curpos - 1
end
end