結果

問題 No.1909 Detect from Substrings
ユーザー 👑 obakyanobakyan
提出日時 2022-04-23 16:19:43
言語 Lua
(LuaJit 2.1.1696795921)
結果
RE  
実行時間 -
コード長 1,347 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 5,336 KB
実行使用メモリ 5,728 KB
最終ジャッジ日時 2023-09-07 09:07:41
合計ジャッジ時間 2,149 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 7 ms
5,676 KB
testcase_09 AC 5 ms
5,672 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 5 ms
5,676 KB
testcase_14 AC 6 ms
5,668 KB
testcase_15 AC 7 ms
5,704 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 7 ms
5,696 KB
testcase_22 AC 6 ms
5,696 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 6 ms
5,612 KB
testcase_27 AC 7 ms
5,612 KB
testcase_28 AC 7 ms
5,620 KB
testcase_29 AC 7 ms
5,660 KB
testcase_30 AC 7 ms
5,676 KB
testcase_31 AC 7 ms
5,604 KB
testcase_32 AC 8 ms
5,616 KB
testcase_33 AC 8 ms
5,676 KB
testcase_34 AC 9 ms
5,728 KB
testcase_35 AC 7 ms
5,672 KB
testcase_36 AC 7 ms
5,716 KB
testcase_37 AC 6 ms
5,684 KB
testcase_38 AC 8 ms
5,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0