結果
| 問題 | No.1909 Detect from Substrings | 
| コンテスト | |
| ユーザー | 👑 | 
| 提出日時 | 2022-04-23 16:19:43 | 
| 言語 | Lua (LuaJit 2.1.1734355927) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,347 bytes | 
| コンパイル時間 | 160 ms | 
| コンパイル使用メモリ | 5,376 KB | 
| 実行使用メモリ | 6,272 KB | 
| 最終ジャッジ日時 | 2024-06-25 03:25:52 | 
| 合計ジャッジ時間 | 1,953 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 20 RE * 16 | 
ソースコード
local n, m = io.read("*n", "*n", "*l")
local s = {}
for i = 1, n do
  s[i] = io.read()
end
local function check(w)
  for i = 1, n do
    local skipped = false
    local si = s[i]
    for j = 1, m + 1 do
      local z = skipped and si:byte(j - 1) or si:byte(j)
      if w:byte(j) ~= z then
        if skipped then 
          return false
        else
          skipped = true
        end
      end
    end
  end
  return true
end
local c = 0
if n == 2 then
  for i = 1, m do
    if s[1]:byte(i) ~= s[2]:byte(i) then
      local w = s[1]:sub(1, i) .. s[2]:sub(i, m)
      if check(w) then
        c = c + 1
      end
      w = s[2]:sub(1, i) .. s[1]:sub(i, m)
      if check(w) then
        c = c + 1
      end
      break
    end
  end
else
  for i = 1, m do
    local t = {}
    local z = 0
    for j = 1, n do
      local b = s[j]:byte(i)
      if not t[b] then
        z = z + 1
        t[b] = {j}
      else
        table.insert(t[b], 0)
      end
    end
    if 2 < z then break end
    if z == 2 then
      local k1, v1 = next(t)
      local k2, v2 = next(t, k1)
      if #v1 == 1 then
        local w = s[k2][1]:sub(1, i) .. s[k1][1]:sub(i, m)
        if check(w) then c = c + 1 end
      else
        local w = s[k1][1]:sub(1, i) .. s[k2][1]:sub(i, m)
        if check(w) then c = c + 1 end
      end
      break
    end
  end
end
print(c)
            
            
            
        