結果
| 問題 | 
                            No.10 +か×か
                             | 
                    
| コンテスト | |
| ユーザー | 
                             core123
                         | 
                    
| 提出日時 | 2019-04-18 11:51:17 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,638 bytes | 
| コンパイル時間 | 2,327 ms | 
| コンパイル使用メモリ | 79,488 KB | 
| 実行使用メモリ | 60,740 KB | 
| 最終ジャッジ日時 | 2024-09-22 09:09:07 | 
| 合計ジャッジ時間 | 4,590 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 7 WA * 5 | 
ソースコード
import java.util.*;
import java.util.stream.*;
import static java.lang.Math.*;
public class Main{
	public static void main(String... args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int total=sc.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
		}
		boolean[][] dp=new boolean[n][total+1];
		dp[0][a[0]]=true;
		for(int i=1;i<dp.length;i++){
			for(int j=1;j<dp[0].length;j++){
				if(j-a[i]>=0){
					if(dp[i-1][j-a[i]]){
						dp[i][j]=true;
						continue;
					}
				}
				if(j%a[i]==0){
					if(dp[i-1][j/a[i]]&&!dp[i][j]){
						dp[i][j]=true;
					}
				}
			}
		}
		
		StringBuilder ans=new StringBuilder();
		for(int i=n-1;i>0;i--){
			if(dp[i-1][total-a[i]]){
				ans.append("+");
				total-=a[i];
				continue;
			}
			if(total%a[i]==0){
				if(dp[i-1][total/a[i]]){
					ans.append("*");
					total/=a[i];
					continue;
				}
			}
			throw new IllegalArgumentException();
		}
		ans.reverse();
		put(ans);
		
	}
	public static class Pair{
		final int x,y;
		Pair(int x,int y){
			this.x=x;
			this.y=y;
		}
		@Override
		public String toString(){
			return String.format("Pair(%d,%d)",x,y);
		}
	}
	public static void print(Object object){
        System.out.print(object);
    }
    public static void put(Object object) {
        System.out.println(object);
    }
    public static void put(){
        System.out.println();
    }
 
    public static void print(String format,Object... args){
        System.out.print(String.format(format,args));
    }
    public static void put(String format,Object... args) {
        System.out.println(String.format(format,args));
    }
}
            
            
            
        
            
core123