結果

問題 No.852 連続部分文字列
ユーザー 👑 obakyanobakyan
提出日時 2020-05-02 17:25:16
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 330 ms / 3,153 ms
コード長 746 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 5,372 KB
実行使用メモリ 17,148 KB
最終ジャッジ日時 2023-08-28 23:57:09
合計ジャッジ時間 5,371 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 5 ms
4,380 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 6 ms
4,376 KB
testcase_32 AC 6 ms
4,384 KB
testcase_33 AC 295 ms
16,640 KB
testcase_34 AC 294 ms
16,676 KB
testcase_35 AC 295 ms
16,596 KB
testcase_36 AC 296 ms
16,716 KB
testcase_37 AC 304 ms
16,792 KB
testcase_38 AC 302 ms
16,836 KB
testcase_39 AC 297 ms
16,484 KB
testcase_40 AC 292 ms
16,528 KB
testcase_41 AC 293 ms
16,808 KB
testcase_42 AC 313 ms
17,148 KB
testcase_43 AC 330 ms
14,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 val = 0
for i = 1, 26 do
  if 0 < #t[i] then
    val = val + n + 1 - t[i][#t[i]]
  end
end
local cnt = 0
for i = 1, n do
  cnt = cnt + val
  local b = s:sub(i, i):byte() - 96
  if t[b][#t[b]] == i then
    val = val - (n + 1 - t[b][#t[b]])
    table.remove(t[b])
    if 0 < #t[b] then
      val = val + (n + 1 - t[b][#t[b]])
    end
  end
end
local all = n * (n + 1) / 2
print(string.format("%.10f", cnt / all))
0