結果

問題 No.672 最長AB列
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2020-01-08 10:09:53
言語 Ruby
(3.3.0)
結果
AC  
実行時間 253 ms / 2,000 ms
コード長 222 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 11,348 KB
実行使用メモリ 37,736 KB
最終ジャッジ日時 2023-08-15 00:20:27
合計ジャッジ時間 6,041 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,116 KB
testcase_01 AC 84 ms
15,264 KB
testcase_02 AC 84 ms
15,164 KB
testcase_03 AC 85 ms
15,240 KB
testcase_04 AC 85 ms
15,092 KB
testcase_05 AC 83 ms
15,136 KB
testcase_06 AC 83 ms
15,036 KB
testcase_07 AC 82 ms
15,028 KB
testcase_08 AC 84 ms
15,308 KB
testcase_09 AC 253 ms
37,736 KB
testcase_10 AC 246 ms
33,332 KB
testcase_11 AC 243 ms
33,160 KB
testcase_12 AC 213 ms
28,232 KB
testcase_13 AC 212 ms
28,436 KB
testcase_14 AC 213 ms
28,336 KB
testcase_15 AC 213 ms
28,288 KB
testcase_16 AC 211 ms
28,540 KB
testcase_17 AC 236 ms
33,136 KB
testcase_18 AC 205 ms
28,172 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def max(a,b); a > b ? a : b; end
S = gets.chomp
M = { 0 => 0 }
d = 0

S.chars.each.with_index(1).inject(0) do |s,(c,i)|
  s += (c == 'A' ? 1 : -1)
  if M[s]
    d = max(d, i - M[s])
  else
    M[s] = i
  end
  s
end
puts d
0