結果

問題 No.10 +か×か
ユーザー GrenacheGrenache
提出日時 2016-05-31 23:14:44
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,221 ms / 5,000 ms
コード長 1,129 bytes
コンパイル時間 4,283 ms
コンパイル使用メモリ 75,908 KB
実行使用メモリ 327,860 KB
最終ジャッジ日時 2023-08-21 06:19:11
合計ジャッジ時間 8,745 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,956 KB
testcase_01 AC 126 ms
53,868 KB
testcase_02 AC 126 ms
55,620 KB
testcase_03 AC 1,161 ms
319,368 KB
testcase_04 AC 203 ms
68,708 KB
testcase_05 AC 130 ms
55,920 KB
testcase_06 AC 1,221 ms
327,860 KB
testcase_07 AC 529 ms
147,820 KB
testcase_08 AC 214 ms
68,724 KB
testcase_09 AC 204 ms
68,508 KB
testcase_10 AC 128 ms
55,780 KB
testcase_11 AC 126 ms
55,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;


public class Main_yukicoder10 {

    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 j = 1; j < n; j++) {
            for (int i = 1; i <= total; i++) {
        		if (dp[j - 1][i] == null) {
        			continue;
        		}

        		if (i * a[j] <= total) {
        			String tmp = dp[j - 1][i] + '*';
        			if (dp[j][i * a[j]] != null && dp[j][i * a[j]].compareTo(tmp) > 0) {
        			} else {
        				dp[j][i * a[j]] = tmp;
        			}
        		}
        		if (i + a[j] <= total) {
        			String tmp = dp[j - 1][i] + '+';
        			if (dp[j][i + a[j]] != null && dp[j][i + a[j]].compareTo(tmp) > 0) {
        			} else {
        				dp[j][i + a[j]] = tmp;
        			}
        		}
        	}
        }

        System.out.println(dp[n - 1][total]);

        sc.close();
    }
}
0