結果
| 問題 |
No.1994 Confusing Name
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2022-07-13 23:09:23 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 459 ms / 2,000 ms |
| コード長 | 1,180 bytes |
| コンパイル時間 | 310 ms |
| コンパイル使用メモリ | 5,120 KB |
| 実行使用メモリ | 17,888 KB |
| 最終ジャッジ日時 | 2024-06-25 04:18:18 |
| 合計ジャッジ時間 | 7,457 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
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"))