提出 #37445876


ソースコード 拡げる

n = gets.chomp.to_i
s = gets.chomp.chars

def triangular(n)
  n * (n + 1) / 2
end

answer = triangular(n)
prev_char = s[0]
continue = 1

1.upto(n - 1) do |i|
  if prev_char != s[i]
    answer -= triangular(continue)
    continue = 1
    prev_char = s[i]
    next
  end

  continue += 1
end

answer -= triangular(continue)

puts answer

提出情報

提出日時
問題 084 - There are two types of characters(★3)
ユーザ thatblue
言語 Ruby (2.7.1)
得点 3
コード長 360 Byte
結果 AC
実行時間 285 ms
メモリ 68868 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 3 / 3
結果
AC × 4
AC × 37
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 09_hand_o.txt, 09_hand_oo.txt, 09_hand_ox.txt, 09_hand_x.txt, 09_hand_xo.txt, 09_hand_xx.txt, 10_small_random_03.txt, 10_small_random_04.txt, 10_small_random_05.txt, 10_small_random_06.txt, 10_small_random_07.txt, 10_small_random_08.txt, 10_small_random_09.txt, 50_large_random_01.txt, 50_large_random_02.txt, 50_large_random_03.txt, 50_large_random_04.txt, 60_alternate_01.txt, 60_alternate_02.txt, 70_o1000000_01.txt, 70_o500000_x500000_01.txt, 70_o999998_x2_01.txt, 70_o999999_x1_01.txt, 70_x1000000_01.txt, 70_x500000_o500000_01.txt, 70_x999998_o2_01.txt, 70_x999999_o1_01.txt, 80_little_o_01.txt, 80_little_o_02.txt, 80_little_o_03.txt, 80_little_x_01.txt, 80_little_x_02.txt, 80_little_x_03.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 55 ms 14280 KiB
00_sample_02.txt AC 56 ms 14044 KiB
00_sample_03.txt AC 55 ms 14288 KiB
00_sample_04.txt AC 55 ms 14060 KiB
09_hand_o.txt AC 56 ms 14144 KiB
09_hand_oo.txt AC 55 ms 14200 KiB
09_hand_ox.txt AC 55 ms 14152 KiB
09_hand_x.txt AC 55 ms 14104 KiB
09_hand_xo.txt AC 55 ms 14192 KiB
09_hand_xx.txt AC 56 ms 14144 KiB
10_small_random_03.txt AC 56 ms 14092 KiB
10_small_random_04.txt AC 54 ms 14112 KiB
10_small_random_05.txt AC 55 ms 14148 KiB
10_small_random_06.txt AC 55 ms 13944 KiB
10_small_random_07.txt AC 55 ms 14128 KiB
10_small_random_08.txt AC 55 ms 14160 KiB
10_small_random_09.txt AC 55 ms 14200 KiB
50_large_random_01.txt AC 262 ms 68612 KiB
50_large_random_02.txt AC 265 ms 68580 KiB
50_large_random_03.txt AC 268 ms 68712 KiB
50_large_random_04.txt AC 261 ms 68868 KiB
60_alternate_01.txt AC 278 ms 68568 KiB
60_alternate_02.txt AC 285 ms 68756 KiB
70_o1000000_01.txt AC 237 ms 68600 KiB
70_o500000_x500000_01.txt AC 235 ms 68728 KiB
70_o999998_x2_01.txt AC 236 ms 68744 KiB
70_o999999_x1_01.txt AC 230 ms 68652 KiB
70_x1000000_01.txt AC 236 ms 68672 KiB
70_x500000_o500000_01.txt AC 235 ms 68508 KiB
70_x999998_o2_01.txt AC 234 ms 68732 KiB
70_x999999_o1_01.txt AC 236 ms 68524 KiB
80_little_o_01.txt AC 235 ms 68432 KiB
80_little_o_02.txt AC 235 ms 68812 KiB
80_little_o_03.txt AC 235 ms 68504 KiB
80_little_x_01.txt AC 235 ms 68640 KiB
80_little_x_02.txt AC 232 ms 68536 KiB
80_little_x_03.txt AC 234 ms 68580 KiB