結果
| 問題 | No.10 +か×か |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-05-31 23:14:44 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 864 ms / 5,000 ms |
| コード長 | 1,129 bytes |
| 記録 | |
| コンパイル時間 | 3,663 ms |
| コンパイル使用メモリ | 88,020 KB |
| 実行使用メモリ | 296,336 KB |
| 最終ジャッジ日時 | 2025-12-06 14:34:52 |
| 合計ジャッジ時間 | 8,123 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 |
ソースコード
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();
}
}