結果

問題 No.154 市バス
ユーザー 👑 obakyanobakyan
提出日時 2020-04-11 21:56:48
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 702 bytes
コンパイル時間 29 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 17:43:49
合計ジャッジ時間 1,204 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
4,348 KB
testcase_01 AC 29 ms
4,348 KB
testcase_02 AC 29 ms
4,348 KB
testcase_03 AC 26 ms
4,348 KB
testcase_04 AC 32 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 23 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local q = io.read("*n", "*l")
for iq = 1, q do
  local s = io.read()
  local red, green = 0, 0
  local wcnt = 0
  local rcnt = 0
  local valid = true
  for i = #s, 1, -1 do
    local w = s:sub(i, i)
    if w == "R" then
      rcnt = rcnt + 1
      red = red + 1
    elseif w == "G" then
      if red == 0 then
        valid = false
        break
      else
        red = red - 1
        green = green + 1
      end
    else
      if green == 0 then
        if wcnt == 0 then
          valid = false
          break
        end
      else
        green = green - 1
        wcnt = wcnt + 1
      end
    end
  end
  if wcnt < rcnt then valid = false end
  print(valid and "possible" or "impossible")
end
0