結果
| 問題 | No.852 連続部分文字列 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-02 17:22:21 |
| 言語 | Lua (LuaJit 2.1.1774638290) |
| 結果 |
AC
|
| 実行時間 | 1,700 ms / 3,153 ms |
| コード長 | 638 bytes |
| 記録 | |
| コンパイル時間 | 256 ms |
| コンパイル使用メモリ | 6,400 KB |
| 実行使用メモリ | 18,128 KB |
| 最終ジャッジ日時 | 2026-06-04 04:48:47 |
| 合計ジャッジ時間 | 20,984 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
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))