結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-26 17:21:23 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 484 bytes |
| コンパイル時間 | 68 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 23,584 KB |
| 最終ジャッジ日時 | 2024-09-16 08:10:55 |
| 合計ジャッジ時間 | 4,874 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 TLE * 1 -- * 9 |
コンパイルメッセージ
Syntax OK
ソースコード
a = gets.chomp
max_length = 0
a_arr = []
current = 0
a_arr << current
a.chars do |c|
if c == "A"
current = current + 1
a_arr << current
end
if c == "B"
current = current - 1
a_arr << current
end
end
a_arr_reverse = a_arr.reverse
(a_arr.min..a_arr.max).each do |i|
next if a_arr.count(i) <= 0
tmp_max_length = a_arr.length - a_arr.index(i) - a_arr_reverse.index(i) - 1
max_length = tmp_max_length if tmp_max_length >= max_length
end
print max_length