結果

問題 No.852 連続部分文字列
ユーザー simansiman
提出日時 2021-12-31 04:34:14
言語 Ruby
(3.3.0)
結果
AC  
実行時間 601 ms / 3,153 ms
コード長 341 bytes
コンパイル時間 45 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 26,112 KB
最終ジャッジ日時 2024-04-16 14:58:46
合計ジャッジ時間 11,915 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
12,416 KB
testcase_01 AC 90 ms
12,416 KB
testcase_02 AC 90 ms
12,544 KB
testcase_03 AC 90 ms
12,416 KB
testcase_04 AC 90 ms
12,544 KB
testcase_05 AC 89 ms
12,288 KB
testcase_06 AC 89 ms
12,416 KB
testcase_07 AC 89 ms
12,544 KB
testcase_08 AC 93 ms
12,672 KB
testcase_09 AC 89 ms
12,288 KB
testcase_10 AC 89 ms
12,416 KB
testcase_11 AC 92 ms
12,544 KB
testcase_12 AC 88 ms
12,416 KB
testcase_13 AC 100 ms
12,672 KB
testcase_14 AC 94 ms
12,544 KB
testcase_15 AC 106 ms
12,544 KB
testcase_16 AC 103 ms
12,544 KB
testcase_17 AC 105 ms
12,672 KB
testcase_18 AC 107 ms
12,672 KB
testcase_19 AC 92 ms
12,544 KB
testcase_20 AC 100 ms
12,544 KB
testcase_21 AC 110 ms
12,800 KB
testcase_22 AC 98 ms
12,672 KB
testcase_23 AC 103 ms
12,544 KB
testcase_24 AC 98 ms
12,672 KB
testcase_25 AC 101 ms
12,672 KB
testcase_26 AC 109 ms
12,672 KB
testcase_27 AC 103 ms
12,672 KB
testcase_28 AC 106 ms
12,672 KB
testcase_29 AC 107 ms
12,672 KB
testcase_30 AC 94 ms
12,416 KB
testcase_31 AC 108 ms
12,800 KB
testcase_32 AC 109 ms
12,672 KB
testcase_33 AC 590 ms
25,088 KB
testcase_34 AC 593 ms
24,832 KB
testcase_35 AC 595 ms
24,832 KB
testcase_36 AC 599 ms
24,832 KB
testcase_37 AC 594 ms
24,448 KB
testcase_38 AC 594 ms
24,576 KB
testcase_39 AC 596 ms
24,704 KB
testcase_40 AC 599 ms
24,064 KB
testcase_41 AC 601 ms
24,960 KB
testcase_42 AC 595 ms
26,112 KB
testcase_43 AC 588 ms
25,088 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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)
0