結果
| 問題 | No.1433 Two color sequence | 
| コンテスト | |
| ユーザー |  Apass | 
| 提出日時 | 2021-03-19 22:46:50 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 364 ms / 2,000 ms | 
| コード長 | 1,112 bytes | 
| コンパイル時間 | 3,818 ms | 
| コンパイル使用メモリ | 78,184 KB | 
| 実行使用メモリ | 54,840 KB | 
| 最終ジャッジ日時 | 2024-11-19 00:06:41 | 
| 合計ジャッジ時間 | 11,172 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
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);
    }
}
            
            
            
        