結果

問題 No.3110 Like CPCTF?
ユーザー tufusa
提出日時 2025-04-18 22:55:15
言語 Ruby
(3.4.1)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 556 bytes
コンパイル時間 806 ms
コンパイル使用メモリ 7,808 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2025-04-18 22:55:18
合計ジャッジ時間 2,423 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
s = gets.chomp.bytes

cs = s.map.with_index { [_1, _2] }.group_by { _1[0] }.transform_values { _1.map { |a| a[1] } }
ans = 0
cs.each do |c1, ids|
  next if ids == 1

  ids.combination(2) do |i1, i3|
    ((i1 + 1)...i3).each do |i2|
      c2 = s[i2]
      next if c2 == c1

      ((i3 + 1)...n).each do |i4|
        c4 = s[i4]
        next if c4 == c1 || c4 == c2

        ((i4 + 1)...n).each do |i5|
          c5 = s[i5]
          next if c5 == c1 || c5 == c4 || c5 == c2

          ans += 1
        end
      end
    end
  end
end

puts ans
0