結果

問題 No.672 最長AB列
ユーザー gemmarogemmaro
提出日時 2020-07-05 09:31:14
言語 Ruby
(3.3.0)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 377 bytes
コンパイル時間 464 ms
コンパイル使用メモリ 11,896 KB
実行使用メモリ 42,268 KB
最終ジャッジ日時 2023-10-22 02:34:40
合計ジャッジ時間 4,681 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
19,228 KB
testcase_01 AC 115 ms
19,232 KB
testcase_02 AC 116 ms
19,232 KB
testcase_03 AC 113 ms
19,232 KB
testcase_04 AC 116 ms
19,232 KB
testcase_05 AC 116 ms
19,232 KB
testcase_06 AC 114 ms
19,232 KB
testcase_07 AC 115 ms
19,232 KB
testcase_08 AC 116 ms
19,232 KB
testcase_09 AC 261 ms
42,268 KB
testcase_10 AC 238 ms
36,712 KB
testcase_11 AC 242 ms
36,712 KB
testcase_12 AC 216 ms
31,012 KB
testcase_13 AC 214 ms
31,012 KB
testcase_14 AC 213 ms
31,012 KB
testcase_15 AC 214 ms
31,012 KB
testcase_16 AC 214 ms
31,012 KB
testcase_17 AC 244 ms
36,712 KB
testcase_18 AC 214 ms
31,012 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

C = 200_000 + 1

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)
    if c[d][0].nil?
      c[d] = [C + i, C + i]
    else
      c[d][1] = C + i
    end
  end
  c.select { _1 && _2 }.map { (_1 - _2).abs }.max
end

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

puts solve
0