結果

問題 No.10 +か×か
ユーザー kou6839kou6839
提出日時 2014-11-11 12:30:16
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 754 bytes
コンパイル時間 2,130 ms
コンパイル使用メモリ 74,672 KB
実行使用メモリ 71,648 KB
最終ジャッジ日時 2023-08-30 03:06:29
合計ジャッジ時間 9,215 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,320 KB
testcase_01 AC 127 ms
55,500 KB
testcase_02 AC 124 ms
55,840 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 

public class Main {
	static int N;
	static int T;
	static int[] a;
	static void dfs(int now,int sum,ArrayList<Character> result ){
		if(now==N-1){
			if(sum==T){
				for(char g:result){
					System.out.print(g);
				}
				return;
			}
			return;
		}
		if(sum>=T) return;
		result.add('+');
		dfs(now+1,sum+a[now+1],result);
		result.remove(result.size()-1);
		result.add('*');
		dfs(now+1,sum*a[now+1],result);
		result.remove(result.size()-1);
		
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		 N = sc.nextInt();
		 T = sc.nextInt();
		 a = new int[N];
		for(int i=0;i<N;i++){
			a[i] = sc.nextInt();
		}
		dfs(0,a[0],new ArrayList<Character>());
		
	}
}
0