結果
問題 | 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 doa[i] = io.read("*n")endfor i = 1, n dob[i] = io.read("*n")endlocal c = {}local tp = {}local csum = 0for i = 1, n doif a[i] < b[i] thentp[i] = "R"c[i] = b[i] - a[i]elseif b[i] < a[i] thentp[i] = "L"c[i] = a[i] - b[i]elsetp[i] = ""c[i] = 0endcsum = csum + c[i]endprint(csum)local curpos = 1while curpos <= n doif tp[curpos] == "R" thenlocal spos = curposlocal tpos = curpos + 1while tpos <= n and tp[tpos] == "R" dotpos = tpos + 1endfor i = tpos - 1, spos, -1 doio.write(string.rep(i .. " R\n", b[i] - a[i]))endcurpos = tposelsecurpos = curpos + 1endendcurpos = nwhile 1 <= curpos doif tp[curpos] == "L" thenlocal spos = curposlocal tpos = curpos - 1while 1 <= tpos and tp[tpos] == "L" dotpos = tpos - 1endfor i = tpos + 1, spos doio.write(string.rep(i .. " L\n", a[i] - b[i]))endcurpos = tposelsecurpos = curpos - 1endend