結果
問題 | No.10 +か×か |
ユーザー | Grenache |
提出日時 | 2016-06-01 00:11:00 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 172 ms / 5,000 ms |
コード長 | 1,137 bytes |
コンパイル時間 | 3,139 ms |
コンパイル使用メモリ | 78,548 KB |
実行使用メモリ | 58,936 KB |
最終ジャッジ日時 | 2024-05-08 11:52:28 |
合計ジャッジ時間 | 5,457 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 126 ms
53,816 KB |
testcase_01 | AC | 123 ms
54,220 KB |
testcase_02 | AC | 113 ms
52,736 KB |
testcase_03 | AC | 172 ms
58,824 KB |
testcase_04 | AC | 157 ms
58,936 KB |
testcase_05 | AC | 128 ms
54,048 KB |
testcase_06 | AC | 156 ms
58,176 KB |
testcase_07 | AC | 165 ms
58,852 KB |
testcase_08 | AC | 128 ms
53,724 KB |
testcase_09 | AC | 142 ms
56,264 KB |
testcase_10 | AC | 113 ms
52,648 KB |
testcase_11 | AC | 118 ms
54,096 KB |
ソースコード
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(); } }