結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-26 17:19:04 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 454 bytes |
| コンパイル時間 | 214 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 21,632 KB |
| 最終ジャッジ日時 | 2024-09-16 07:55:56 |
| 合計ジャッジ時間 | 4,823 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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|
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