結果

問題 No.505 カードの数式2
ユーザー akitsu818akitsu818
提出日時 2017-04-30 18:08:55
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 642 bytes
コンパイル時間 2,118 ms
コンパイル使用メモリ 71,416 KB
実行使用メモリ 58,044 KB
最終ジャッジ日時 2023-10-11 23:51:59
合計ジャッジ時間 8,887 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,724 KB
testcase_01 AC 128 ms
55,796 KB
testcase_02 AC 213 ms
55,904 KB
testcase_03 AC 124 ms
56,028 KB
testcase_04 AC 124 ms
56,136 KB
testcase_05 AC 124 ms
55,728 KB
testcase_06 AC 124 ms
55,904 KB
testcase_07 AC 127 ms
55,688 KB
testcase_08 AC 126 ms
55,708 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 125 ms
55,648 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 124 ms
55,632 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 126 ms
55,720 KB
testcase_20 AC 131 ms
55,720 KB
testcase_21 AC 217 ms
55,640 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	static int target;
	public static void main(String argas[]){

		Scanner cin = new Scanner(System.in);

		target = cin.nextInt();
		int list[] = new int[target];

		for(int i=0;i<target;i++){
			list[i] = cin.nextInt();
		}
		cin.close();
		System.out.println(dfs(0,0,list));
	}

	static int dfs(int count,int sum,int array[]){
		if(count==target-1){
			return Math.max(sum*array[count], Math.max(sum+array[count],sum-array[count]));
		}else{
			return Math.max(dfs(count+1,sum*array[count],array), Math.max(dfs(count+1,sum+array[count],array), dfs(count+1,sum-array[count],array)));
		}
	}

}
0