結果

問題 No.505 カードの数式2
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2017-04-21 23:24:37
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 750 bytes
コンパイル時間 2,227 ms
コンパイル使用メモリ 74,324 KB
実行使用メモリ 60,376 KB
最終ジャッジ日時 2023-09-27 23:21:58
合計ジャッジ時間 5,601 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
60,376 KB
testcase_01 AC 113 ms
56,636 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] A = new int [N];
        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
        }
        solve(N,A);
    }
    static int ans;
    static void solve(int N, int[]A){
        ans = Integer.MIN_VALUE;
        funtion(N,A,1,A[0]);
        System.out.println(ans);
    }
    static void funtion(int N, int[]A, int k, int X){
        if(N==k){
            ans=Math.max(ans,X);
        }else{
            funtion(N,A,k+1,X+A[k]);
            funtion(N,A,k+1,X-A[k]);
            funtion(N,A,k+1,X*A[k]);
            if(A[k]!=0)funtion(N,A,k+1,X/A[k]);
        }
    }
}
0