結果
| 問題 |
No.1433 Two color sequence
|
| コンテスト | |
| ユーザー |
Apass
|
| 提出日時 | 2021-03-19 22:44:20 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,072 bytes |
| コンパイル時間 | 3,851 ms |
| コンパイル使用メモリ | 77,996 KB |
| 実行使用メモリ | 65,804 KB |
| 最終ジャッジ日時 | 2024-11-19 00:01:42 |
| 合計ジャッジ時間 | 10,546 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 WA * 1 |
ソースコード
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 answer = 0;
long maxPos = Math.max(0, a[0]);
long minNeg = Math.min(0, a[0]);
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