結果

問題 No.10 +か×か
ユーザー kou6839kou6839
提出日時 2014-11-11 12:37:01
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 765 bytes
コンパイル時間 2,013 ms
コンパイル使用メモリ 74,900 KB
実行使用メモリ 61,648 KB
最終ジャッジ日時 2023-08-30 03:07:04
合計ジャッジ時間 9,292 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,672 KB
testcase_01 AC 123 ms
55,464 KB
testcase_02 AC 124 ms
55,628 KB
testcase_03 AC 177 ms
56,912 KB
testcase_04 TLE -
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);
				}
				System.exit(0);
			}
			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