結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-26 16:04:16 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 634 bytes |
| コンパイル時間 | 372 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 39,964 KB |
| 最終ジャッジ日時 | 2024-09-16 05:11:31 |
| 合計ジャッジ時間 | 4,992 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 1 WA * 5 TLE * 1 -- * 9 |
コンパイルメッセージ
Syntax OK
ソースコード
a = gets.chomp
max_length = 0
if a.to_s.count('A') == 0 || a.to_s.count('B') == 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
end
puts max_length