結果
| 問題 |
No.852 連続部分文字列
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2020-05-02 17:22:21 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 638 bytes |
| コンパイル時間 | 577 ms |
| コンパイル使用メモリ | 5,376 KB |
| 実行使用メモリ | 18,640 KB |
| 最終ジャッジ日時 | 2024-12-30 15:24:38 |
| 合計ジャッジ時間 | 36,111 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 TLE * 1 |
ソースコード
local s = io.read()
local n = #s
local t = {}
for i = 1, 26 do
t[i] = {}
end
for i = 1, n do
local b = s:sub(i, i):byte() - 96
table.insert(t[b], i)
end
-- inv sort
for i = 1, 26 do
local tn = #t[i]
local htn = math.floor(tn / 2)
for j = 1, htn do
t[i][j], t[i][tn + 1 - j] = t[i][tn + 1 - j], t[i][j]
end
end
local cnt = 0
for i = 1, n do
for j = 1, 26 do
if 0 < #t[j] then
local pos = t[j][#t[j]]
cnt = cnt + n + 1 - pos
end
end
local b = s:sub(i, i):byte() - 96
if t[b][#t[b]] == i then
table.remove(t[b])
end
end
local all = n * (n + 1) / 2
print(string.format("%.10f", cnt / all))