結果

問題 No.505 カードの数式2
ユーザー atkrym1217atkrym1217
提出日時 2017-04-26 12:30:03
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 686 bytes
コンパイル時間 4,067 ms
コンパイル使用メモリ 71,268 KB
実行使用メモリ 56,356 KB
最終ジャッジ日時 2023-10-11 15:13:26
合計ジャッジ時間 7,403 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,884 KB
testcase_01 AC 123 ms
55,508 KB
testcase_02 AC 123 ms
55,728 KB
testcase_03 AC 122 ms
56,224 KB
testcase_04 AC 122 ms
55,680 KB
testcase_05 AC 123 ms
55,776 KB
testcase_06 AC 123 ms
55,976 KB
testcase_07 AC 121 ms
55,928 KB
testcase_08 AC 123 ms
55,840 KB
testcase_09 AC 122 ms
55,592 KB
testcase_10 AC 122 ms
55,388 KB
testcase_11 AC 123 ms
55,780 KB
testcase_12 AC 123 ms
56,024 KB
testcase_13 WA -
testcase_14 AC 122 ms
55,980 KB
testcase_15 WA -
testcase_16 AC 122 ms
55,908 KB
testcase_17 AC 123 ms
55,500 KB
testcase_18 AC 124 ms
55,968 KB
testcase_19 WA -
testcase_20 AC 123 ms
55,800 KB
testcase_21 AC 127 ms
56,140 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 120 ms
56,024 KB
testcase_30 AC 122 ms
56,036 KB
testcase_31 AC 124 ms
56,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0;i < n;i++) a[i] = sc.nextInt();
        long[] dp = new long[100];
        dp[0] = a[0];
        for (int i = 1;i < n;i++) {
            long tmp = Long.MIN_VALUE;
            tmp = Math.max(tmp, dp[i-1]+a[i]);
            tmp = Math.max(tmp, dp[i-1]-a[i]);
            tmp = Math.max(tmp, dp[i-1]*a[i]);
            if (a[i]!=0) tmp = Math.max(tmp, dp[i-1]/a[i]);
            dp[i] = tmp;
        }
        System.out.println(dp[n-1]);
    }
}
0