結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー 👑 obakyanobakyan
提出日時 2022-04-24 22:18:29
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 7,060 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2023-09-08 16:17:16
合計ジャッジ時間 2,934 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 283 ms
4,376 KB
testcase_01 AC 256 ms
4,380 KB
testcase_02 AC 233 ms
9,380 KB
testcase_03 AC 229 ms
12,416 KB
testcase_04 AC 244 ms
12,320 KB
testcase_05 AC 224 ms
12,368 KB
testcase_06 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local good = "good"
local problem = "problem"
local g = {}
for i = 1, 4 do g[i] = good:sub(i, i) end
local p = {}
for i = 1, 7 do p[i] = problem:sub(i, i) end

local function solve()
  local s = io.read()
  local n = #s
  local t = {}
  for i = 1, n - 6 do
    t[i] = 0
  end
  t[n - 5] = 1000000007
  for i = n - 6, 1, -1 do
    local c = 0
    for j = 0, 6 do
      if p[1 + j] ~= s:sub(i + j, i + j) then
        c = c + 1
      end
    end
    t[i] = mmi(c, t[i + 1])
  end
  local ans = 1000000007
  local u = 1000000007
  local bias = 0
  for i = 1, n - 10 do
    if 7 < i then
      local f = true
      for j = i - 7, i - 1 do
        if p[j - i + 8] ~= s:sub(j, j) then
          f = false break
        end
      end
      if f then bias = bias + 1 end
    end
    local c = bias
    for j = 0, 3 do
      if g[1 + j] ~= s:sub(i + j, i + j) then
        c = c + 1
      end
    end
    u = mmi(u, c)
    ans = mmi(ans, u + t[i + 4])
  end
  print(ans)
end

local q = io.read("*n", "*l")
for iq = 1, q do
  solve()
end
0