結果

問題 No.1160 Strange Bowling
ユーザー tentententen
提出日時 2023-08-01 18:34:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 1,844 bytes
コンパイル時間 2,848 ms
コンパイル使用メモリ 95,220 KB
実行使用メモリ 48,620 KB
最終ジャッジ日時 2024-04-19 17:44:45
合計ジャッジ時間 9,409 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
36,716 KB
testcase_01 AC 48 ms
37,332 KB
testcase_02 AC 47 ms
36,928 KB
testcase_03 AC 48 ms
36,860 KB
testcase_04 AC 48 ms
37,208 KB
testcase_05 AC 49 ms
36,844 KB
testcase_06 AC 46 ms
36,924 KB
testcase_07 AC 46 ms
37,064 KB
testcase_08 AC 46 ms
36,832 KB
testcase_09 AC 46 ms
36,924 KB
testcase_10 AC 225 ms
47,364 KB
testcase_11 AC 167 ms
44,908 KB
testcase_12 AC 144 ms
43,644 KB
testcase_13 AC 127 ms
41,128 KB
testcase_14 AC 204 ms
46,116 KB
testcase_15 AC 133 ms
42,624 KB
testcase_16 AC 136 ms
43,884 KB
testcase_17 AC 202 ms
47,472 KB
testcase_18 AC 170 ms
44,924 KB
testcase_19 AC 154 ms
44,040 KB
testcase_20 AC 181 ms
46,992 KB
testcase_21 AC 173 ms
44,652 KB
testcase_22 AC 130 ms
42,148 KB
testcase_23 AC 128 ms
41,964 KB
testcase_24 AC 125 ms
41,684 KB
testcase_25 AC 154 ms
44,228 KB
testcase_26 AC 133 ms
42,604 KB
testcase_27 AC 188 ms
46,628 KB
testcase_28 AC 141 ms
43,760 KB
testcase_29 AC 209 ms
46,416 KB
testcase_30 AC 241 ms
48,620 KB
testcase_31 AC 186 ms
46,380 KB
testcase_32 AC 140 ms
43,664 KB
testcase_33 AC 168 ms
45,408 KB
testcase_34 AC 165 ms
44,640 KB
testcase_35 AC 214 ms
48,092 KB
testcase_36 AC 48 ms
36,968 KB
testcase_37 AC 46 ms
37,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        int[][] dp = new int[n + 1][2];
        dp[0][1] = Integer.MIN_VALUE;
        for (int i = 1; i <= n; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            dp[i][0] = Math.max(dp[i - 1][0] + a, dp[i - 1][1] + a * 2);
            dp[i][1] = Math.max(dp[i - 1][0] + b, dp[i - 1][1] + b * 2);
        }
        System.out.println(Math.max(dp[n][0], dp[n][1]));
    }
} 
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();
    }
    
}
0