結果
問題 |
No.10 +か×か
|
ユーザー |
![]() |
提出日時 | 2015-08-03 15:22:14 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 874 ms / 5,000 ms |
コード長 | 1,543 bytes |
コンパイル時間 | 2,517 ms |
コンパイル使用メモリ | 79,120 KB |
実行使用メモリ | 94,400 KB |
最終ジャッジ日時 | 2024-12-14 15:30:53 |
合計ジャッジ時間 | 6,161 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
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; } }