結果
問題 | No.10 +か×か |
ユーザー | mastersatoshi |
提出日時 | 2015-08-03 15:22:14 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 918 ms / 5,000 ms |
コード長 | 1,543 bytes |
コンパイル時間 | 2,832 ms |
コンパイル使用メモリ | 74,724 KB |
実行使用メモリ | 100,472 KB |
最終ジャッジ日時 | 2023-08-21 06:13:39 |
合計ジャッジ時間 | 6,060 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
50,220 KB |
testcase_01 | AC | 51 ms
49,632 KB |
testcase_02 | AC | 51 ms
49,932 KB |
testcase_03 | AC | 918 ms
93,480 KB |
testcase_04 | AC | 123 ms
56,520 KB |
testcase_05 | AC | 51 ms
49,804 KB |
testcase_06 | AC | 901 ms
100,472 KB |
testcase_07 | AC | 373 ms
81,628 KB |
testcase_08 | AC | 168 ms
60,948 KB |
testcase_09 | AC | 158 ms
61,416 KB |
testcase_10 | AC | 51 ms
49,712 KB |
testcase_11 | AC | 50 ms
49,708 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int total = Integer.parseInt(br.readLine()); String[] tmpA = br.readLine().split(" "); int[] a = new int[tmpA.length]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(tmpA[i]); } String now[] = new String[total + 1]; String next[] = new String[total + 1]; int no1 = a[0]; now[no1] = ""; for (int i = 1; i < n; i++) { for (int j = 0; j <= total; j++) { if (now[j] == null) { continue; } int nextAdd = j + a[i]; int nextTime = j * a[i]; if (nextAdd <= total) { next[nextAdd] = compare(next[nextAdd], now[j] + "+"); } if (nextTime <= total) { next[nextTime] = compare(next[nextTime], now[j] + "*"); } } now = next.clone(); next = new String[total + 1]; } System.out.println(now[total]); } private static String compare(String setted, String next) { if (setted == null) { return next; } if (setted.compareTo(next) < 0) { return next; } return setted; } }