結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-02-08 00:50:28 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 227 ms / 2,000 ms |
| コード長 | 309 bytes |
| コンパイル時間 | 86 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 36,224 KB |
| 最終ジャッジ日時 | 2024-06-26 08:48:32 |
| 合計ジャッジ時間 | 3,830 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
コンパイルメッセージ
Syntax OK
ソースコード
answer = cumulative_sum = 0
distribution = { 0 => -1 }
gets.chomp.chars.each_with_index do |char, i|
cumulative_sum += char == 'A' ? 1 : -1
if distribution.key?(cumulative_sum)
answer = [answer, i - distribution[cumulative_sum]].max
else
distribution[cumulative_sum] = i
end
end
puts answer