結果

問題 No.10 +か×か
ユーザー 37zigen37zigen
提出日時 2016-03-09 16:09:35
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,091 bytes
コンパイル時間 3,747 ms
コンパイル使用メモリ 78,584 KB
実行使用メモリ 57,832 KB
最終ジャッジ日時 2023-10-24 21:46:32
合計ジャッジ時間 5,960 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,460 KB
testcase_01 AC 129 ms
57,628 KB
testcase_02 AC 132 ms
57,692 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 125 ms
56,480 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.Scanner;
import java.io.PrintWriter;
import java.util.ArrayList;
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){
		//System.out.println("now="+now+" sum="+sum);
		//for(char g:result){
			//System.out.print(g);
		//}
		if(now==n-1){
			if(sum==t){
				PrintWriter pw=new PrintWriter(System.out);
				for(char g:result){
					pw.print(g);
				}
				pw.close();
				System.exit(0);
			}
			return;
		}
		if(sum>t)return;
		if(dp[sum][now])return;
		dp[now][sum]=true;
		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);
		return;
	}
	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][10001];
		 dfs(0,a[0],new ArrayList<Character>());
		 
		 
		 sc.close();
	}
}
0