結果
問題 |
No.10 +か×か
|
ユーザー |
|
提出日時 | 2016-05-31 23:33:27 |
言語 | Java (openjdk 23) |
結果 |
MLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,306 bytes |
コンパイル時間 | 4,296 ms |
コンパイル使用メモリ | 82,912 KB |
実行使用メモリ | 585,316 KB |
最終ジャッジ日時 | 2024-12-14 15:37:18 |
合計ジャッジ時間 | 14,414 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 MLE * 2 |
ソースコード
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(); } }