結果

問題 No.1433 Two color sequence
コンテスト
ユーザー ks2m
提出日時 2021-03-19 21:52:15
言語 Java
(openjdk 27.0.1.0.3 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 267 ms / 2,000 ms
+ 284µs
コード長 757 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,525 ms
コンパイル使用メモリ 93,980 KB
実行使用メモリ 67,412 KB
最終ジャッジ日時 2026-10-29 01:22:06
合計ジャッジ時間 8,241 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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