結果

問題 No.1433 Two color sequence
ユーザー ks2mks2m
提出日時 2021-03-19 21:52:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 388 ms / 2,000 ms
コード長 757 bytes
コンパイル時間 3,110 ms
コンパイル使用メモリ 76,636 KB
実行使用メモリ 60,136 KB
最終ジャッジ日時 2024-04-29 16:38:42
合計ジャッジ時間 11,678 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
36,488 KB
testcase_01 AC 51 ms
36,428 KB
testcase_02 AC 51 ms
36,832 KB
testcase_03 AC 260 ms
56,784 KB
testcase_04 AC 273 ms
56,504 KB
testcase_05 AC 52 ms
36,796 KB
testcase_06 AC 52 ms
36,932 KB
testcase_07 AC 54 ms
36,696 KB
testcase_08 AC 347 ms
60,028 KB
testcase_09 AC 366 ms
59,224 KB
testcase_10 AC 352 ms
58,708 KB
testcase_11 AC 353 ms
58,836 KB
testcase_12 AC 354 ms
59,796 KB
testcase_13 AC 358 ms
59,776 KB
testcase_14 AC 388 ms
60,024 KB
testcase_15 AC 364 ms
60,136 KB
testcase_16 AC 364 ms
59,964 KB
testcase_17 AC 369 ms
59,616 KB
testcase_18 AC 366 ms
59,616 KB
testcase_19 AC 372 ms
59,908 KB
testcase_20 AC 366 ms
60,096 KB
testcase_21 AC 367 ms
59,696 KB
testcase_22 AC 359 ms
60,072 KB
testcase_23 AC 351 ms
59,788 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