結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-26 16:01:29 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 554 bytes |
| コンパイル時間 | 244 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 43,552 KB |
| 最終ジャッジ日時 | 2024-09-16 05:11:25 |
| 合計ジャッジ時間 | 4,604 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 TLE * 1 -- * 9 |
コンパイルメッセージ
Syntax OK
ソースコード
a = gets.chomp
max_length = 0
(0..a.length).each do |i|
descend_str_length = a[0, i].to_s.length
descend_str_A = a[0, i].to_s.count('A')
ascend_str_length = a[i, a.length].to_s.length
ascend_str_A = a[i, a.length].to_s.count('A')
balanced_length = descend_str_length / 2 == descend_str_A ? descend_str_A * 2 : 0
max_length = balanced_length if balanced_length >= max_length
balanced_length = ascend_str_length / 2 == ascend_str_A ? ascend_str_A * 2 : 0
max_length = balanced_length if balanced_length >= max_length
end
puts max_length