結果

問題 No.1292 パタパタ三角形
ユーザー 👑 obakyanobakyan
提出日時 2020-11-24 23:22:39
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 891 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 12,772 KB
最終ジャッジ日時 2023-10-01 01:18:46
合計ジャッジ時間 1,515 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 27 ms
4,376 KB
testcase_08 AC 42 ms
4,376 KB
testcase_09 AC 42 ms
9,428 KB
testcase_10 AC 59 ms
9,288 KB
testcase_11 AC 59 ms
9,276 KB
testcase_12 AC 65 ms
11,780 KB
testcase_13 AC 31 ms
12,772 KB
testcase_14 AC 12 ms
4,376 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local s = io.read()
local t = {}
t[0] = {}
t[0][0] = true
local row, col = 0, 0
local top, left, right = 1, 2, 3
local bottom = 0
local ret = 1
local function register()
  if not t[row] then t[row] = {} end
  if not t[row][col] then ret = ret + 1 end
  t[row][col] = true
end
for i = 1, #s do
  local b = s:byte(i) - 96
  if i % 2 == 1 then
    if top == b then
      bottom = top
      row = row - 1
    elseif left == b then
      left, right, bottom = top, left, right
      col = col - 1
    else--if right == b then
      left, right, bottom = right, top, left
      col = col + 1
    end
  else
    if bottom == b then
      top = bottom
      row = row + 1
    elseif left == b then
      left, right, top = bottom, left, right
      col = col - 1
    else--if right == b then
      left, right, top = right, bottom, left
      col = col + 1
    end
  end
  register()
end
print(ret)
0