結果
| 問題 | 
                            No.1646 Avoid Palindrome
                             | 
                    
| コンテスト | |
| ユーザー | 
                            👑  | 
                    
| 提出日時 | 2021-08-13 21:50:19 | 
| 言語 | Lua  (LuaJit 2.1.1734355927)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,298 bytes | 
| コンパイル時間 | 229 ms | 
| コンパイル使用メモリ | 6,820 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-03 18:26:51 | 
| 合計ジャッジ時間 | 1,636 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 9 WA * 31 | 
ソースコード
local mod = 998244353
local mfl = math.floor
local function bmul(x, y)
  local x0, y0 = x % 31596, y % 31596
  local x1, y1 = mfl(x / 31596), mfl(y / 31596)
  return (x1 * y1 * 62863 + (x1 * y0 + x0 * y1) * 31596 + x0 * y0) % mod
end
local n = io.read("*n", "*l")
local s = io.read()
local t = {}
for i = 1, n do
  t[i] = s:sub(i, i)
end
for i = 1, n - 1 do
  if t[i] == t[i + 1] and t[i] ~= "?" then
    print(0) os.exit()
  end
end
for i = 1, n - 2 do
  if t[i] == t[i + 2] and t[i] ~= "?" then
    print(0) os.exit()
  end
end
local ret = 1
for i = 1, n do
  local c = 0
  if t[i] == "?" then
    if 2 < i then
      c = c + 1
    end
    if 1 < i then
      c = c + 1
    end
    if i <= n - 1 then
      if t[i + 1] ~= "?" then
        local f = true
        if 2 < i and t[i - 2] == t[i + 1] then f = false end
        if 1 < i and t[i - 1] == t[i + 1] then f = false end
        if f then c = c + 1 end
      end
    end
    if i <= n - 2 then
      if t[i + 2] ~= "?" then
        local f = true
        if 2 < i and t[i - 2] == t[i + 2] then f = false end
        if 1 < i and t[i - 1] == t[i + 2] then f = false end
        if t[i + 1] == t[i + 2] then f = false end
        if f then c = c + 1 end
      end
    end
    -- print(26 - c)
    ret = bmul(ret, 26 - c)
  end
end
print(ret)