結果

問題 No.10 +か×か
ユーザー GrenacheGrenache
提出日時 2016-05-31 23:33:27
言語 Java21
(openjdk 21)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,306 bytes
コンパイル時間 3,495 ms
コンパイル使用メモリ 84,020 KB
実行使用メモリ 596,188 KB
最終ジャッジ日時 2024-05-08 11:53:05
合計ジャッジ時間 13,832 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
54,092 KB
testcase_01 AC 113 ms
52,876 KB
testcase_02 AC 126 ms
53,888 KB
testcase_03 MLE -
testcase_04 AC 399 ms
65,228 KB
testcase_05 AC 130 ms
54,084 KB
testcase_06 MLE -
testcase_07 AC 1,141 ms
211,472 KB
testcase_08 AC 486 ms
82,808 KB
testcase_09 AC 489 ms
71,864 KB
testcase_10 AC 146 ms
54,220 KB
testcase_11 AC 131 ms
54,208 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