結果

問題 No.2419 MMA文字列2
ユーザー simansiman
提出日時 2023-08-13 17:20:52
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,778 ms / 2,000 ms
コード長 223 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 11,420 KB
実行使用メモリ 15,808 KB
最終ジャッジ日時 2023-08-13 17:21:16
合計ジャッジ時間 22,179 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,276 KB
testcase_01 AC 80 ms
15,132 KB
testcase_02 AC 82 ms
15,252 KB
testcase_03 AC 82 ms
15,140 KB
testcase_04 AC 81 ms
15,080 KB
testcase_05 AC 82 ms
15,288 KB
testcase_06 AC 80 ms
15,268 KB
testcase_07 AC 81 ms
15,112 KB
testcase_08 AC 81 ms
15,240 KB
testcase_09 AC 80 ms
15,244 KB
testcase_10 AC 81 ms
15,284 KB
testcase_11 AC 83 ms
15,092 KB
testcase_12 AC 448 ms
15,204 KB
testcase_13 AC 139 ms
15,400 KB
testcase_14 AC 776 ms
15,432 KB
testcase_15 AC 542 ms
15,336 KB
testcase_16 AC 819 ms
15,532 KB
testcase_17 AC 296 ms
15,176 KB
testcase_18 AC 838 ms
15,392 KB
testcase_19 AC 877 ms
15,388 KB
testcase_20 AC 326 ms
15,248 KB
testcase_21 AC 278 ms
15,308 KB
testcase_22 AC 1,401 ms
15,804 KB
testcase_23 AC 1,408 ms
15,752 KB
testcase_24 AC 1,381 ms
15,788 KB
testcase_25 AC 1,385 ms
15,700 KB
testcase_26 AC 231 ms
15,332 KB
testcase_27 AC 1,366 ms
15,620 KB
testcase_28 AC 1,778 ms
15,560 KB
testcase_29 AC 1,720 ms
15,808 KB
testcase_30 AC 1,741 ms
15,800 KB
testcase_31 AC 1,744 ms
15,536 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

S = gets.chomp
counter = Hash.new(0)

ans = 0

S.each_char do |s|
  ('A'..'Z').each do |c|
    next if s == c
    cnt = counter[c]
    next if cnt <= 1

    ans += cnt * (cnt - 1) / 2
  end

  counter[s] += 1
end

puts ans
0