結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-05-31 23:14:44 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,368 ms / 5,000 ms |
| コード長 | 1,129 bytes |
| コンパイル時間 | 3,711 ms |
| コンパイル使用メモリ | 80,492 KB |
| 実行使用メモリ | 318,552 KB |
| 最終ジャッジ日時 | 2024-12-14 15:36:19 |
| 合計ジャッジ時間 | 9,034 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
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();
}
}