結果

問題 No.852 連続部分文字列
ユーザー 👑 obakyanobakyan
提出日時 2020-05-02 17:22:21
言語 Lua
(LuaJit 2.1.1696795921)
結果
TLE  
実行時間 -
コード長 638 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 7,156 KB
実行使用メモリ 17,468 KB
最終ジャッジ日時 2023-08-28 23:50:02
合計ジャッジ時間 36,953 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 18 ms
4,376 KB
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 42 ms
4,376 KB
testcase_16 AC 18 ms
4,376 KB
testcase_17 AC 25 ms
4,384 KB
testcase_18 AC 44 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 14 ms
4,376 KB
testcase_21 AC 46 ms
4,376 KB
testcase_22 AC 9 ms
4,376 KB
testcase_23 AC 22 ms
4,376 KB
testcase_24 AC 11 ms
4,380 KB
testcase_25 AC 21 ms
4,380 KB
testcase_26 AC 45 ms
4,380 KB
testcase_27 AC 18 ms
4,380 KB
testcase_28 AC 23 ms
4,376 KB
testcase_29 AC 46 ms
4,376 KB
testcase_30 AC 5 ms
4,376 KB
testcase_31 AC 48 ms
4,376 KB
testcase_32 AC 48 ms
4,376 KB
testcase_33 AC 3,150 ms
16,752 KB
testcase_34 AC 3,142 ms
16,988 KB
testcase_35 AC 3,101 ms
17,004 KB
testcase_36 AC 2,981 ms
16,848 KB
testcase_37 AC 3,099 ms
17,020 KB
testcase_38 AC 3,019 ms
16,912 KB
testcase_39 AC 3,018 ms
16,704 KB
testcase_40 AC 3,024 ms
16,700 KB
testcase_41 AC 3,053 ms
16,872 KB
testcase_42 TLE -
testcase_43 AC 2,315 ms
15,056 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 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))
0