結果
問題 |
No.672 最長AB列
|
ユーザー |
|
提出日時 | 2019-01-26 15:28:29 |
言語 | Ruby (3.4.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 470 bytes |
コンパイル時間 | 39 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 23,424 KB |
最終ジャッジ日時 | 2024-09-16 05:10:43 |
合計ジャッジ時間 | 4,677 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 RE * 2 |
other | AC * 2 RE * 5 TLE * 1 -- * 8 |
コンパイルメッセージ
Syntax OK
ソースコード
a = gets.chomp max_length = 0 (0..a.length).each do |i| descend_str, ascend_str = a[0, i-1].to_s, a[i-1, a.length].to_s balanced_length = descend_str.length if descend_str.count('A') == descend_str.count('B') max_length = balanced_length if ((balanced_length || 0) >= max_length) balanced_length = ascend_str.length if ascend_str.count('A') == ascend_str.count('B') max_length = balanced_length if ((balanced_length || 0) >= max_length) end puts max_length