結果

問題 No.1433 Two color sequence
ユーザー tentententen
提出日時 2022-08-04 18:43:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 1,299 bytes
コンパイル時間 2,079 ms
コンパイル使用メモリ 75,020 KB
実行使用メモリ 66,240 KB
最終ジャッジ日時 2023-10-12 16:40:32
合計ジャッジ時間 11,515 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,836 KB
testcase_01 AC 43 ms
49,516 KB
testcase_02 AC 42 ms
49,628 KB
testcase_03 AC 227 ms
58,676 KB
testcase_04 AC 234 ms
59,180 KB
testcase_05 AC 43 ms
49,392 KB
testcase_06 AC 42 ms
49,360 KB
testcase_07 AC 43 ms
49,268 KB
testcase_08 AC 284 ms
65,024 KB
testcase_09 AC 382 ms
66,240 KB
testcase_10 AC 362 ms
65,924 KB
testcase_11 AC 370 ms
65,552 KB
testcase_12 AC 389 ms
65,388 KB
testcase_13 AC 373 ms
65,988 KB
testcase_14 AC 357 ms
64,308 KB
testcase_15 AC 354 ms
65,804 KB
testcase_16 AC 380 ms
64,828 KB
testcase_17 AC 350 ms
63,864 KB
testcase_18 AC 349 ms
66,156 KB
testcase_19 AC 350 ms
65,400 KB
testcase_20 AC 353 ms
65,420 KB
testcase_21 AC 385 ms
64,096 KB
testcase_22 AC 385 ms
65,868 KB
testcase_23 AC 372 ms
65,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        char[] colors = sc.next().toCharArray();
        long[] sums = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            sums[i] = sums[i - 1];
            int x = sc.nextInt();
            if (colors[i - 1] == 'R') {
                sums[i] += x;
            } else {
                sums[i] -= x;
            }
        }
        Arrays.sort(sums);
        System.out.println(sums[n] - sums[0]);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0