結果

問題 No.672 最長AB列
ユーザー letrangerjpletrangerjp
提出日時 2018-04-14 00:06:45
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 349 bytes
コンパイル時間 433 ms
コンパイル使用メモリ 11,416 KB
実行使用メモリ 33,188 KB
最終ジャッジ日時 2023-09-10 04:17:00
合計ジャッジ時間 5,179 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,240 KB
testcase_01 AC 82 ms
15,264 KB
testcase_02 AC 82 ms
15,072 KB
testcase_03 AC 83 ms
15,028 KB
testcase_04 AC 82 ms
15,108 KB
testcase_05 AC 84 ms
15,124 KB
testcase_06 AC 84 ms
15,100 KB
testcase_07 AC 83 ms
15,036 KB
testcase_08 AC 82 ms
15,028 KB
testcase_09 AC 267 ms
32,972 KB
testcase_10 AC 232 ms
32,908 KB
testcase_11 AC 230 ms
32,900 KB
testcase_12 AC 270 ms
33,156 KB
testcase_13 WA -
testcase_14 AC 231 ms
33,012 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 272 ms
33,004 KB
testcase_18 AC 242 ms
33,188 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

S = gets.chomp.chars
A = [sum = 0]+S.map{|c|sum += c == ?A ? 1 : 0}
B = [sum = 0]+S.map{|c|sum += c == ?B ? 1 : 0}

ans = 0
l = 0
r = 0
while r < A.size
  a = A[r] - A[l]
  b = B[r] - B[l]
  ra = A[-1] - A[r]
  rb = B[-1] - B[r]
  if rb < a - b || ra < b - a
    l += 1
  else
    r += 1
  end
  if a == b
    ans = a*2 if a*2 > ans
  end
end
p ans
0