結果
問題 | No.1433 Two color sequence |
ユーザー | tenten |
提出日時 | 2023-04-17 09:56:13 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 392 ms / 2,000 ms |
コード長 | 2,115 bytes |
コンパイル時間 | 2,573 ms |
コンパイル使用メモリ | 91,644 KB |
実行使用メモリ | 54,848 KB |
最終ジャッジ日時 | 2024-04-20 16:20:54 |
合計ジャッジ時間 | 10,957 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
37,220 KB |
testcase_01 | AC | 59 ms
37,108 KB |
testcase_02 | AC | 55 ms
37,176 KB |
testcase_03 | AC | 250 ms
45,548 KB |
testcase_04 | AC | 231 ms
45,700 KB |
testcase_05 | AC | 59 ms
36,924 KB |
testcase_06 | AC | 55 ms
37,060 KB |
testcase_07 | AC | 55 ms
36,960 KB |
testcase_08 | AC | 319 ms
54,512 KB |
testcase_09 | AC | 366 ms
54,136 KB |
testcase_10 | AC | 346 ms
54,460 KB |
testcase_11 | AC | 344 ms
54,432 KB |
testcase_12 | AC | 350 ms
54,848 KB |
testcase_13 | AC | 319 ms
54,468 KB |
testcase_14 | AC | 332 ms
53,684 KB |
testcase_15 | AC | 330 ms
54,224 KB |
testcase_16 | AC | 330 ms
54,416 KB |
testcase_17 | AC | 319 ms
54,496 KB |
testcase_18 | AC | 356 ms
54,364 KB |
testcase_19 | AC | 324 ms
54,036 KB |
testcase_20 | AC | 324 ms
54,300 KB |
testcase_21 | AC | 392 ms
54,184 KB |
testcase_22 | AC | 350 ms
54,520 KB |
testcase_23 | AC | 329 ms
54,064 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); char[] colors = sc.next().toCharArray(); long current = 0; long min = 0; long max = 0; long minValue = Long.MAX_VALUE; long maxValue = Long.MIN_VALUE; for (int i = 0; i < n; i++) { int x = sc.nextInt(); if (colors[i] == 'R') { current += x; } else { current -= x; } minValue = Math.min(minValue, current - max); maxValue = Math.max(maxValue, current - min); min = Math.min(min, current); max = Math.max(max, current); } System.out.println(Math.max(maxValue, -minValue)); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }