結果
| 問題 |
No.505 カードの数式2
|
| コンテスト | |
| ユーザー |
akitsu818
|
| 提出日時 | 2017-04-30 18:21:10 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 915 bytes |
| コンパイル時間 | 2,510 ms |
| コンパイル使用メモリ | 77,308 KB |
| 実行使用メモリ | 54,436 KB |
| 最終ジャッジ日時 | 2024-09-13 23:53:46 |
| 合計ジャッジ時間 | 24,363 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 TLE * 1 |
| other | AC * 22 WA * 2 TLE * 5 |
ソースコード
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(1,list[0],list));
}
static int dfs(int count,int sum,int array[]){
if(count==target-1){
if(array[count]!=0){
return Math.max(Math.max(sum*array[count],(int)sum/array[count]), Math.max(sum+array[count],sum-array[count]));
}else{
return Math.max(0, sum+array[count]);
}
}else{
if(array[count]!=0){
return Math.max(Math.max(dfs(count+1,sum*array[count],array),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));
}
}
}
}
akitsu818