結果
| 問題 | No.10 +か×か |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-06-01 00:11:00 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 177 ms / 5,000 ms |
| コード長 | 1,137 bytes |
| 記録 | |
| コンパイル時間 | 3,824 ms |
| コンパイル使用メモリ | 81,352 KB |
| 実行使用メモリ | 52,032 KB |
| 最終ジャッジ日時 | 2025-12-06 14:34:59 |
| 合計ジャッジ時間 | 6,626 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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();
}
boolean[][] dp = new boolean[n][total + 1];
dp[n - 1][total] = true;
for (int j = n - 1; j > 0; j--) {
for (int i = 1; i <= total; i++) {
if (i * a[j] <= total && dp[j][i * a[j]]) {
dp[j - 1][i] = true;
}
if (i + a[j] <= total && dp[j][i + a[j]]) {
dp[j - 1][i] = true;
}
}
}
String ret = "";
int j = a[0];
for (int i = 1; i < n; i++) {
if (j + a[i] <= total && dp[i][j + a[i]]) {
ret += "+";
j += a[i];
} else if (j * a[i] <= total && dp[i][j * a[i]]){
ret += "*";
j *= a[i];
} else {
System.out.println("error");
}
}
System.out.println(ret);
sc.close();
}
}