結果
問題 |
No.672 最長AB列
|
ユーザー |
![]() |
提出日時 | 2019-01-26 16:50:48 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 361 ms / 2,000 ms |
コード長 | 324 bytes |
コンパイル時間 | 111 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 41,216 KB |
最終ジャッジ日時 | 2024-09-16 05:58:08 |
合計ジャッジ時間 | 5,332 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
コンパイルメッセージ
Syntax OK
ソースコード
S = gets.strip L = S.size occurrences = Array.new( L * 2 + 2 ) { Array.new } occurrences[L] << 0 depth = 0 L.times do |i| depth += if S[i] == 'A' then 1 else -1 end occurrences[ L + depth ] << i + 1 end res = 0 occurrences.each do |ary| if !ary.empty? then res = [ res, ary.last - ary.first ].max end end puts res