結果

問題 No.1994 Confusing Name
ユーザー 👑 obakyanobakyan
提出日時 2022-07-13 23:09:23
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 716 ms / 2,000 ms
コード長 1,180 bytes
コンパイル時間 529 ms
コンパイル使用メモリ 5,328 KB
実行使用メモリ 18,740 KB
最終ジャッジ日時 2023-09-07 10:02:29
合計ジャッジ時間 12,326 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,388 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 7 ms
4,384 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 572 ms
16,252 KB
testcase_13 AC 672 ms
16,608 KB
testcase_14 AC 684 ms
18,036 KB
testcase_15 AC 545 ms
13,996 KB
testcase_16 AC 460 ms
13,420 KB
testcase_17 AC 514 ms
13,980 KB
testcase_18 AC 701 ms
18,436 KB
testcase_19 AC 716 ms
18,376 KB
testcase_20 AC 708 ms
18,740 KB
testcase_21 AC 96 ms
5,840 KB
testcase_22 AC 42 ms
4,384 KB
testcase_23 AC 550 ms
14,604 KB
testcase_24 AC 547 ms
16,248 KB
testcase_25 AC 300 ms
10,660 KB
testcase_26 AC 135 ms
6,684 KB
testcase_27 AC 501 ms
14,664 KB
testcase_28 AC 350 ms
11,576 KB
testcase_29 AC 34 ms
4,380 KB
testcase_30 AC 384 ms
13,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local n = io.read("*n", "*l")
local s = {}
local lenmap = {}
local ans = {}
local tmp = {}
for i = 1, n do
  ans[i] = 0
  tmp[i] = ""
  s[i] = io.read()
  local len = #s[i]
  if not lenmap[len] then lenmap[len] = {} end
  table.insert(lenmap[len], i)
end

for len, tbl in pairs(lenmap) do
  local sidx = {}
  for i = 1, #tbl do
    local idx = tbl[i]
    table.insert(sidx, idx)
  end
  for pos = 1, len do
    for i = 1, #tbl do
      local idx = tbl[i]
      if pos == 1 then
        tmp[idx] = s[idx]:sub(2, len)
      elseif pos == len then
        tmp[idx] = s[idx]:sub(1, len - 1)
      else
        tmp[idx] = s[idx]:sub(1, pos - 1) .. s[idx]:sub(pos + 1, len)
      end
    end
    table.sort(sidx, function(a, b) return tmp[a] < tmp[b] end)
    local left = 1
    for i = 1, #tbl - 1 do
      local i1, i2 = sidx[i], sidx[i + 1]
      if tmp[i1] ~= tmp[i2] then
        local z = i - left
        for j = left, i do
          ans[sidx[j]] = ans[sidx[j]] + z
        end
        left = i + 1
      end
    end
    do
      local z = #tbl - left
      for j = left, #tbl do
        ans[sidx[j]] = ans[sidx[j]] + z
      end
    end
  end
end
print(table.concat(ans, "\n"))
0