結果

問題 No.1433 Two color sequence
ユーザー ApassApass
提出日時 2021-03-19 22:46:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 329 ms / 2,000 ms
コード長 1,112 bytes
コンパイル時間 3,081 ms
コンパイル使用メモリ 77,860 KB
実行使用メモリ 55,128 KB
最終ジャッジ日時 2024-04-29 18:08:43
合計ジャッジ時間 9,959 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
36,832 KB
testcase_01 AC 48 ms
37,008 KB
testcase_02 AC 49 ms
36,812 KB
testcase_03 AC 197 ms
45,972 KB
testcase_04 AC 194 ms
46,008 KB
testcase_05 AC 49 ms
37,072 KB
testcase_06 AC 48 ms
36,728 KB
testcase_07 AC 48 ms
36,728 KB
testcase_08 AC 295 ms
54,424 KB
testcase_09 AC 329 ms
55,128 KB
testcase_10 AC 290 ms
54,496 KB
testcase_11 AC 297 ms
54,168 KB
testcase_12 AC 295 ms
54,500 KB
testcase_13 AC 287 ms
54,356 KB
testcase_14 AC 306 ms
54,576 KB
testcase_15 AC 318 ms
54,060 KB
testcase_16 AC 319 ms
54,256 KB
testcase_17 AC 328 ms
54,240 KB
testcase_18 AC 319 ms
54,148 KB
testcase_19 AC 286 ms
54,360 KB
testcase_20 AC 316 ms
54,464 KB
testcase_21 AC 294 ms
54,620 KB
testcase_22 AC 290 ms
54,548 KB
testcase_23 AC 324 ms
54,576 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 maxPos = Math.max(0, a[0]);
        long minNeg = Math.min(0, a[0]);
        long answer = Math.max(maxPos, -minNeg);
        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