結果

問題 No.1160 Strange Bowling
ユーザー tentententen
提出日時 2023-02-16 16:23:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 1,844 bytes
コンパイル時間 3,307 ms
コンパイル使用メモリ 91,116 KB
実行使用メモリ 60,052 KB
最終ジャッジ日時 2023-09-25 20:52:57
合計ジャッジ時間 10,914 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,288 KB
testcase_01 AC 45 ms
49,864 KB
testcase_02 AC 44 ms
49,556 KB
testcase_03 AC 45 ms
49,352 KB
testcase_04 AC 44 ms
49,288 KB
testcase_05 AC 45 ms
49,516 KB
testcase_06 AC 44 ms
49,452 KB
testcase_07 AC 45 ms
49,320 KB
testcase_08 AC 43 ms
49,408 KB
testcase_09 AC 43 ms
49,508 KB
testcase_10 AC 210 ms
58,960 KB
testcase_11 AC 170 ms
56,236 KB
testcase_12 AC 145 ms
55,136 KB
testcase_13 AC 123 ms
54,708 KB
testcase_14 AC 207 ms
60,052 KB
testcase_15 AC 125 ms
55,120 KB
testcase_16 AC 141 ms
55,480 KB
testcase_17 AC 201 ms
59,668 KB
testcase_18 AC 179 ms
55,044 KB
testcase_19 AC 159 ms
55,004 KB
testcase_20 AC 187 ms
59,372 KB
testcase_21 AC 175 ms
56,940 KB
testcase_22 AC 128 ms
54,496 KB
testcase_23 AC 129 ms
55,096 KB
testcase_24 AC 124 ms
54,664 KB
testcase_25 AC 154 ms
55,316 KB
testcase_26 AC 132 ms
55,408 KB
testcase_27 AC 176 ms
55,512 KB
testcase_28 AC 126 ms
55,080 KB
testcase_29 AC 212 ms
58,224 KB
testcase_30 AC 244 ms
59,796 KB
testcase_31 AC 191 ms
57,068 KB
testcase_32 AC 133 ms
54,952 KB
testcase_33 AC 170 ms
55,536 KB
testcase_34 AC 171 ms
55,804 KB
testcase_35 AC 233 ms
59,592 KB
testcase_36 AC 45 ms
49,420 KB
testcase_37 AC 44 ms
49,720 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();
        long[][] dp = new long[n][2];
        dp[0][0] = sc.nextInt();
        dp[0][1] = sc.nextInt();
        for (int i = 1; i < n; i++) {
            int p = sc.nextInt();
            int a = sc.nextInt();
            dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1] + p) + p;
            dp[i][1] = Math.max(dp[i - 1][0], dp[i - 1][1] + a) + a;
        }
        System.out.println(dp[n - 1][0]);
    }
}
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