結果
| 問題 | No.252 "良問"(良問とは言っていない (2) | 
| コンテスト | |
| ユーザー | 👑 | 
| 提出日時 | 2022-04-24 22:18:29 | 
| 言語 | Lua (LuaJit 2.1.1734355927) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 346 ms / 2,000 ms | 
| コード長 | 1,064 bytes | 
| コンパイル時間 | 157 ms | 
| コンパイル使用メモリ | 6,816 KB | 
| 実行使用メモリ | 12,820 KB | 
| 最終ジャッジ日時 | 2024-06-26 09:12:30 | 
| 合計ジャッジ時間 | 3,376 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 7 | 
ソースコード
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
            
            
            
        