結果

問題 No.10 +か×か
ユーザー core123core123
提出日時 2019-04-18 14:26:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,524 ms / 5,000 ms
コード長 1,476 bytes
コンパイル時間 2,347 ms
コンパイル使用メモリ 83,628 KB
実行使用メモリ 353,056 KB
最終ジャッジ日時 2023-08-21 06:26:03
合計ジャッジ時間 8,467 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,796 KB
testcase_01 AC 123 ms
55,932 KB
testcase_02 AC 125 ms
56,404 KB
testcase_03 AC 1,524 ms
344,624 KB
testcase_04 AC 285 ms
74,980 KB
testcase_05 AC 130 ms
56,380 KB
testcase_06 AC 1,487 ms
353,056 KB
testcase_07 AC 643 ms
148,540 KB
testcase_08 AC 320 ms
75,160 KB
testcase_09 AC 330 ms
76,892 KB
testcase_10 AC 130 ms
56,000 KB
testcase_11 AC 127 ms
55,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
		}
		String[][] dp=new String[n][total+1];
		dp[0][a[0]]="";
		for(int i=1;i<dp.length;i++){
			for(int j=1;j<dp[0].length;j++){
				List<String> list=new ArrayList<>();
				if(j-a[i]>=0&&dp[i-1][j-a[i]]!=null){
					list.add(dp[i-1][j-a[i]]+"+");
				}
				if(j%a[i]==0&&dp[i-1][j/a[i]]!=null){
					list.add(dp[i-1][j/a[i]]+"*");
				}
				if(list.size()>0){
					if(list.size()>1){
						Collections.sort(list,Collections.reverseOrder());
					}
					dp[i][j]=list.get(0);
				}
			}
		}
		put(dp[n-1][total]);
	}
	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));
    }
}
0