結果
| 問題 |
No.852 連続部分文字列
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-12-31 04:34:14 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 581 ms / 3,153 ms |
| コード長 | 341 bytes |
| コンパイル時間 | 421 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 25,984 KB |
| 最終ジャッジ日時 | 2024-10-07 11:25:39 |
| 合計ジャッジ時間 | 12,107 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
コンパイルメッセージ
Syntax OK
ソースコード
S = gets.chomp
N = S.size
A = N * (1 + N) / 2
P = Hash.new { |h, k| h[k] = [0] }
N.times do |i|
s = S[i]
P[s] << i + 1
end
sum = 0
P.each do |_, positions|
positions << N + 1
cnt = 0
positions.each_cons(2) do |i, j|
l = j - i - 1
cnt += l * (1 + l) / 2
end
sum += A - cnt
end
puts Rational(sum, A).to_f.round(12)
siman