結果

問題 No.1433 Two color sequence
ユーザー maguroflymagurofly
提出日時 2021-03-19 22:15:06
言語 Ruby
(3.3.0)
結果
AC  
実行時間 377 ms / 2,000 ms
コード長 533 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 11,356 KB
実行使用メモリ 42,580 KB
最終ジャッジ日時 2023-08-12 02:35:34
合計ジャッジ時間 9,356 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,088 KB
testcase_01 AC 78 ms
15,040 KB
testcase_02 AC 78 ms
15,308 KB
testcase_03 AC 341 ms
40,716 KB
testcase_04 AC 341 ms
40,724 KB
testcase_05 AC 78 ms
15,160 KB
testcase_06 AC 78 ms
15,128 KB
testcase_07 AC 77 ms
15,276 KB
testcase_08 AC 346 ms
42,316 KB
testcase_09 AC 350 ms
42,272 KB
testcase_10 AC 339 ms
41,800 KB
testcase_11 AC 342 ms
42,180 KB
testcase_12 AC 354 ms
42,360 KB
testcase_13 AC 349 ms
42,388 KB
testcase_14 AC 355 ms
42,580 KB
testcase_15 AC 354 ms
42,412 KB
testcase_16 AC 355 ms
42,460 KB
testcase_17 AC 354 ms
42,344 KB
testcase_18 AC 352 ms
42,272 KB
testcase_19 AC 353 ms
42,472 KB
testcase_20 AC 355 ms
42,504 KB
testcase_21 AC 377 ms
42,288 KB
testcase_22 AC 353 ms
42,332 KB
testcase_23 AC 354 ms
42,320 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:17: warning: assigned but unused variable - r
Syntax OK

ソースコード

diff #

N = gets.to_i
S = gets.chomp
a = gets.split.map(&:to_i)
S.each_char.with_index do |c, i|
    a[i] *= -1 if c == ?B
end

def find_max_continuous_subsequence(a)
    cumsum = [0]
    a.each do |x|
        cumsum << cumsum[-1] + x
    end
    cummax = [0]
    cumsum.reverse_each do |x|
        cummax.unshift [cummax[0], x].max
    end
    r = a.size
    (0 ... a.size).map { |l| cummax[l + 1] - cumsum[l] }.max
end

ans = find_max_continuous_subsequence(a)
a.map! { |x| -x }
ans = [ans, find_max_continuous_subsequence(a)].max
puts ans
0