結果

問題 No.672 最長AB列
ユーザー gemmarogemmaro
提出日時 2020-07-05 09:27:58
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 406 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 11,900 KB
実行使用メモリ 35,032 KB
最終ジャッジ日時 2023-10-22 02:30:49
合計ジャッジ時間 5,686 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
17,664 KB
testcase_01 AC 101 ms
17,664 KB
testcase_02 AC 100 ms
17,664 KB
testcase_03 AC 102 ms
17,664 KB
testcase_04 AC 102 ms
17,664 KB
testcase_05 AC 103 ms
17,664 KB
testcase_06 AC 102 ms
17,664 KB
testcase_07 AC 100 ms
17,664 KB
testcase_08 AC 99 ms
17,664 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 224 ms
35,032 KB
testcase_12 AC 199 ms
29,444 KB
testcase_13 AC 198 ms
29,444 KB
testcase_14 AC 199 ms
29,444 KB
testcase_15 AC 199 ms
29,444 KB
testcase_16 AC 200 ms
29,444 KB
testcase_17 AC 232 ms
35,032 KB
testcase_18 AC 199 ms
29,444 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

C = 100_000

def solve
  c = Array.new(2 * C, [nil, nil])
  c[C] = [C-1, C-1]
  d = C
  S.each_with_index do |s, i|
    s ? (d += 1) : (d -= 1)
    #pp d
    if c[d][0].nil?
      c[d] = [C + i, C + i]
    else
      c[d][1] = C + i
    end
  end
  #pp c.select{_1&&_2}
  c.select { _1 && _2 }.map { (_1 - _2).abs }.max
end

S = gets.chomp.chars.map { _1 == 'A' }

puts solve
0