結果

問題 No.1433 Two color sequence
ユーザー ks2mks2m
提出日時 2021-03-19 21:52:15
言語 Java19
(openjdk 21)
結果
AC  
実行時間 349 ms / 2,000 ms
コード長 757 bytes
コンパイル時間 4,142 ms
コンパイル使用メモリ 73,708 KB
実行使用メモリ 73,268 KB
最終ジャッジ日時 2023-08-12 01:56:19
合計ジャッジ時間 11,679 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,292 KB
testcase_01 AC 39 ms
49,528 KB
testcase_02 AC 40 ms
49,128 KB
testcase_03 AC 257 ms
65,800 KB
testcase_04 AC 238 ms
68,056 KB
testcase_05 AC 41 ms
49,352 KB
testcase_06 AC 41 ms
49,432 KB
testcase_07 AC 40 ms
49,144 KB
testcase_08 AC 306 ms
71,664 KB
testcase_09 AC 318 ms
71,516 KB
testcase_10 AC 319 ms
71,176 KB
testcase_11 AC 313 ms
71,772 KB
testcase_12 AC 330 ms
71,384 KB
testcase_13 AC 338 ms
71,412 KB
testcase_14 AC 318 ms
71,404 KB
testcase_15 AC 309 ms
71,600 KB
testcase_16 AC 322 ms
71,340 KB
testcase_17 AC 349 ms
71,444 KB
testcase_18 AC 315 ms
71,404 KB
testcase_19 AC 328 ms
71,220 KB
testcase_20 AC 310 ms
71,128 KB
testcase_21 AC 322 ms
73,268 KB
testcase_22 AC 322 ms
71,804 KB
testcase_23 AC 316 ms
71,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		char[] s = br.readLine().toCharArray();
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long max = 0;
		long min = 0;
		long[] b = new long[n + 1];
		for (int i = 0; i < n; i++) {
			if (s[i] == 'R') {
				b[i + 1] = b[i] + a[i];
			} else {
				b[i + 1] = b[i] - a[i];
			}
			max = Math.max(max, b[i + 1]);
			min = Math.min(min, b[i + 1]);
		}
		System.out.println(max - min);
	}
}
0