結果

問題 No.1433 Two color sequence
ユーザー ApassApass
提出日時 2021-03-19 22:44:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,072 bytes
コンパイル時間 3,078 ms
コンパイル使用メモリ 77,956 KB
実行使用メモリ 55,324 KB
最終ジャッジ日時 2024-04-29 18:04:32
合計ジャッジ時間 9,736 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
37,100 KB
testcase_01 AC 46 ms
37,016 KB
testcase_02 AC 47 ms
37,096 KB
testcase_03 AC 200 ms
46,016 KB
testcase_04 AC 206 ms
46,200 KB
testcase_05 WA -
testcase_06 AC 49 ms
36,904 KB
testcase_07 AC 48 ms
37,024 KB
testcase_08 AC 309 ms
54,520 KB
testcase_09 AC 304 ms
54,788 KB
testcase_10 AC 279 ms
54,696 KB
testcase_11 AC 311 ms
54,444 KB
testcase_12 AC 278 ms
55,324 KB
testcase_13 AC 312 ms
54,692 KB
testcase_14 AC 304 ms
54,344 KB
testcase_15 AC 264 ms
54,864 KB
testcase_16 AC 308 ms
54,360 KB
testcase_17 AC 304 ms
54,640 KB
testcase_18 AC 288 ms
54,688 KB
testcase_19 AC 286 ms
54,392 KB
testcase_20 AC 292 ms
54,596 KB
testcase_21 AC 280 ms
54,520 KB
testcase_22 AC 283 ms
54,544 KB
testcase_23 AC 287 ms
54,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class B_TwoColorSequence {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer st;

    private static int readInt() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }

    public static void main(String[] args) throws IOException {
        int N = readInt();
        String paint = br.readLine();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) a[i] = readInt()
                * (paint.charAt(i) == 'R' ? -1 : 1);

        long answer = 0;
        long maxPos = Math.max(0, a[0]);
        long minNeg = Math.min(0, a[0]);
        for (int i = 1; i < N; i++) {
            maxPos = Math.max(maxPos + a[i], 0);
            answer = Math.max(answer, maxPos);
            minNeg = Math.min(minNeg + a[i], 0);
            answer = Math.max(answer, -minNeg);
        }

        System.out.println(answer);
    }
}
0