結果
| 問題 | No.1433 Two color sequence |
| コンテスト | |
| ユーザー |
Apass
|
| 提出日時 | 2021-03-19 22:46:50 |
| 言語 | Java (openjdk 27 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 220 ms / 2,000 ms |
| + 238µs | |
| コード長 | 1,112 bytes |
| 記録 | |
| コンパイル時間 | 2,187 ms |
| コンパイル使用メモリ | 86,152 KB |
| 実行使用メモリ | 60,564 KB |
| 最終ジャッジ日時 | 2026-09-26 10:04:11 |
| 合計ジャッジ時間 | 9,742 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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);
}
}
Apass