結果

問題 No.505 カードの数式2
ユーザー atkrym1217atkrym1217
提出日時 2017-04-26 12:49:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 800 bytes
コンパイル時間 2,082 ms
コンパイル使用メモリ 71,884 KB
実行使用メモリ 56,668 KB
最終ジャッジ日時 2023-10-11 15:14:23
合計ジャッジ時間 9,047 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,876 KB
testcase_01 AC 126 ms
56,092 KB
testcase_02 AC 244 ms
55,576 KB
testcase_03 AC 124 ms
56,024 KB
testcase_04 AC 123 ms
55,612 KB
testcase_05 AC 125 ms
55,948 KB
testcase_06 AC 125 ms
55,956 KB
testcase_07 AC 124 ms
56,084 KB
testcase_08 AC 122 ms
55,828 KB
testcase_09 AC 123 ms
55,552 KB
testcase_10 AC 123 ms
55,612 KB
testcase_11 WA -
testcase_12 AC 124 ms
55,924 KB
testcase_13 AC 125 ms
56,256 KB
testcase_14 AC 124 ms
56,324 KB
testcase_15 AC 125 ms
55,704 KB
testcase_16 AC 125 ms
56,232 KB
testcase_17 WA -
testcase_18 AC 126 ms
55,456 KB
testcase_19 AC 126 ms
56,008 KB
testcase_20 AC 134 ms
55,848 KB
testcase_21 AC 256 ms
56,192 KB
testcase_22 AC 242 ms
55,948 KB
testcase_23 AC 242 ms
56,200 KB
testcase_24 AC 241 ms
56,668 KB
testcase_25 AC 244 ms
55,724 KB
testcase_26 AC 245 ms
56,244 KB
testcase_27 AC 243 ms
54,476 KB
testcase_28 AC 244 ms
56,612 KB
testcase_29 WA -
testcase_30 AC 237 ms
55,532 KB
testcase_31 AC 244 ms
56,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static int n;
    public static int[] a;
    public static int[] b;
    public static long ret = Long.MIN_VALUE;
    public static void main(String[] args) throws Exception {
        n = sc.nextInt();
        a = new int[n];
        b = new int[n];
        for (int i = 0;i < n;i++) a[i] = sc.nextInt();
        calc(0, a[0]);
        System.out.println(ret);
    }
    
    public static void calc(int c, long val) {
        if (c==n-1) {
            ret = Math.max(ret,val);
            return;
        }
        for (int i = 0;i < 3;i++) {
            if (i==0) calc(c+1,val+a[c+1]);
            if (i==1) calc(c+1,val-a[c+1]);
            if (i==2) calc(c+1,val*a[c+1]);
        }
    }
}
0