結果

問題 No.505 カードの数式2
ユーザー akitsu818akitsu818
提出日時 2017-04-30 18:46:42
言語 Java19
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,242 bytes
コンパイル時間 2,348 ms
コンパイル使用メモリ 79,288 KB
実行使用メモリ 56,880 KB
最終ジャッジ日時 2023-08-09 01:52:14
合計ジャッジ時間 13,301 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,124 KB
testcase_01 AC 117 ms
56,052 KB
testcase_02 AC 296 ms
56,808 KB
testcase_03 AC 118 ms
55,904 KB
testcase_04 AC 117 ms
56,140 KB
testcase_05 AC 120 ms
55,820 KB
testcase_06 AC 115 ms
55,664 KB
testcase_07 AC 117 ms
55,676 KB
testcase_08 AC 116 ms
55,960 KB
testcase_09 AC 117 ms
56,340 KB
testcase_10 AC 116 ms
56,160 KB
testcase_11 AC 117 ms
56,172 KB
testcase_12 AC 117 ms
55,796 KB
testcase_13 AC 117 ms
56,228 KB
testcase_14 AC 119 ms
56,328 KB
testcase_15 AC 119 ms
54,128 KB
testcase_16 AC 119 ms
55,948 KB
testcase_17 AC 120 ms
55,920 KB
testcase_18 AC 121 ms
56,044 KB
testcase_19 AC 118 ms
55,824 KB
testcase_20 AC 143 ms
56,728 KB
testcase_21 AC 143 ms
56,880 KB
testcase_22 AC 534 ms
55,788 KB
testcase_23 AC 363 ms
54,692 KB
testcase_24 AC 167 ms
56,432 KB
testcase_25 AC 194 ms
56,784 KB
testcase_26 AC 1,068 ms
56,124 KB
testcase_27 AC 371 ms
56,020 KB
testcase_28 AC 909 ms
55,808 KB
testcase_29 AC 118 ms
55,920 KB
testcase_30 AC 242 ms
56,504 KB
testcase_31 TLE -
権限があれば一括ダウンロードができます

ソースコード

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();
		long list[] = new long[target];

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

	static long dfs(int count,long sum,long array[]){
		if(count==target-1){
			if(array[count]!=0L){
				if(sum<0L){
					return Math.max(Math.max(sum*array[count],(long)sum/array[count]), Math.max(sum+array[count],sum-array[count]));
				}else{
					return Math.max(sum*array[count], Math.max(sum+array[count],sum-array[count]));
				}
			}else{
				return Math.max(0, sum+array[count]);
			}
		}else{
			if(array[count]!=0L){
				if(sum<0L&&array[count]!=1){
					return Math.max(Math.max(dfs(count+1,sum*array[count],array),dfs(count+1,(long)sum/array[count],array)), Math.max(dfs(count+1,sum+array[count],array), dfs(count+1,sum-array[count],array)));
				}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)));
				}
			}else{
				return Math.max(dfs(count+1,0,array), dfs(count+1,sum,array));
			}
		}
	}

}
0