結果

問題 No.10 +か×か
ユーザー kou6839kou6839
提出日時 2014-11-11 12:44:12
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 891 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 74,504 KB
実行使用メモリ 63,332 KB
最終ジャッジ日時 2023-08-30 03:06:46
合計ジャッジ時間 4,864 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
60,468 KB
testcase_01 AC 125 ms
59,860 KB
testcase_02 AC 126 ms
60,072 KB
testcase_03 AC 178 ms
62,056 KB
testcase_04 AC 167 ms
61,884 KB
testcase_05 WA -
testcase_06 AC 221 ms
62,800 KB
testcase_07 WA -
testcase_08 AC 164 ms
62,136 KB
testcase_09 AC 163 ms
61,532 KB
testcase_10 AC 129 ms
59,968 KB
testcase_11 AC 128 ms
60,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 

public class Main {
	static int N;
	static int T;
	static int[] a;
	static boolean[][] dp;
	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;
		if(dp[now][sum]) return;
		result.add('+');
		dfs(now+1,sum+a[now+1],result);
		dp[now][sum] =true;
		result.remove(result.size()-1);
		result.add('*');
		dfs(now+1,sum*a[now+1],result);
		dp[now][sum]=true;
		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();
		}
		dp=new boolean[51][100001];
		dfs(0,a[0],new ArrayList<Character>());
		
	}
}
0