結果

問題 No.10 +か×か
ユーザー GrenacheGrenache
提出日時 2016-05-31 23:33:27
言語 Java21
(openjdk 21)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,306 bytes
コンパイル時間 3,757 ms
コンパイル使用メモリ 81,260 KB
実行使用メモリ 558,476 KB
最終ジャッジ日時 2023-08-21 06:20:25
合計ジャッジ時間 14,069 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
56,100 KB
testcase_01 AC 125 ms
55,796 KB
testcase_02 AC 127 ms
56,464 KB
testcase_03 MLE -
testcase_04 AC 461 ms
67,932 KB
testcase_05 AC 130 ms
55,772 KB
testcase_06 MLE -
testcase_07 AC 967 ms
206,028 KB
testcase_08 AC 503 ms
84,628 KB
testcase_09 AC 483 ms
74,428 KB
testcase_10 AC 143 ms
56,296 KB
testcase_11 AC 127 ms
55,804 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();
        }

        List<Map<Integer, String>> dp = new ArrayList<>();
        for (int i = 0; i < n; i++) {
        	dp.add(new HashMap<>());
        }
        dp.get(0).put(a[0], "");

        for (int j = 1; j < n; j++) {
            for (int i = 1; i <= total; i++) {
        		if (!dp.get(j - 1).containsKey(i)) {
        			continue;
        		}

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

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

        sc.close();
    }
}
0