結果

問題 No.1433 Two color sequence
ユーザー tentententen
提出日時 2021-03-22 12:06:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 886 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 3,916 ms
コンパイル使用メモリ 83,600 KB
実行使用メモリ 67,000 KB
最終ジャッジ日時 2024-05-03 01:45:59
合計ジャッジ時間 20,456 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
54,064 KB
testcase_01 AC 111 ms
53,856 KB
testcase_02 AC 104 ms
52,912 KB
testcase_03 AC 623 ms
61,536 KB
testcase_04 AC 635 ms
62,708 KB
testcase_05 AC 114 ms
53,976 KB
testcase_06 AC 101 ms
52,720 KB
testcase_07 AC 109 ms
54,076 KB
testcase_08 AC 714 ms
64,488 KB
testcase_09 AC 778 ms
66,732 KB
testcase_10 AC 708 ms
66,544 KB
testcase_11 AC 780 ms
64,372 KB
testcase_12 AC 770 ms
64,152 KB
testcase_13 AC 886 ms
64,464 KB
testcase_14 AC 736 ms
64,252 KB
testcase_15 AC 825 ms
64,348 KB
testcase_16 AC 729 ms
64,436 KB
testcase_17 AC 768 ms
67,000 KB
testcase_18 AC 773 ms
64,656 KB
testcase_19 AC 832 ms
66,568 KB
testcase_20 AC 732 ms
64,428 KB
testcase_21 AC 818 ms
64,620 KB
testcase_22 AC 724 ms
64,656 KB
testcase_23 AC 819 ms
64,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] colors = sc.next().toCharArray();
        long min = 0;
        long max = 0;
        long value = 0;
        long ans = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            if (colors[i] == 'B') {
                x *= -1;
            }
            value += x;
            ans = Math.max(ans, value - min);
            ans = Math.max(ans, max - value);
            min = Math.min(min, value);
            max = Math.max(max, value);
        } 
        System.out.println(ans);
    }
}
0