結果

問題 No.10 +か×か
ユーザー t8m8⛄️t8m8⛄️
提出日時 2016-02-12 15:30:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,519 ms / 5,000 ms
コード長 1,731 bytes
コンパイル時間 3,655 ms
コンパイル使用メモリ 81,036 KB
実行使用メモリ 414,944 KB
最終ジャッジ日時 2023-08-21 06:17:50
合計ジャッジ時間 9,552 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
56,184 KB
testcase_01 AC 137 ms
56,432 KB
testcase_02 AC 136 ms
55,664 KB
testcase_03 AC 1,519 ms
414,944 KB
testcase_04 AC 252 ms
79,916 KB
testcase_05 AC 145 ms
55,948 KB
testcase_06 AC 1,278 ms
379,196 KB
testcase_07 AC 690 ms
197,448 KB
testcase_08 AC 261 ms
77,076 KB
testcase_09 AC 232 ms
69,960 KB
testcase_10 AC 138 ms
55,836 KB
testcase_11 AC 137 ms
55,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class No0010 {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		int n = in.nextInt();
		int t = in.nextInt();
		int[] a = new int[n];
		for (int i=0; i<n; i++) {
			a[i] = in.nextInt();
		}

		StringBuilder[][] dp = new StringBuilder[n][t+1];
		dp[0][a[0]] = new StringBuilder();
		for (int i=0; i<n-1; i++) {
			for (int j=0; j<t+1; j++) {
				if (dp[i][j] == null) continue;

				if (j + a[i+1] < t+1) {
					if (dp[i+1][j+a[i+1]] == null) {
						dp[i+1][j+a[i+1]] = new StringBuilder(dp[i][j]);
						dp[i+1][j+a[i+1]].append('+');
					} else {
						StringBuilder sb = new StringBuilder();
						sb.append(dp[i][j]).append('+');
						if (sb.toString().compareTo(dp[i+1][j+a[i+1]].toString()) > 0) {
							dp[i+1][j+a[i+1]] = sb;
						}
					}
				}


				if (j * a[i+1] < t+1) {
					if (dp[i+1][j*a[i+1]] == null) {
						dp[i+1][j*a[i+1]] = new StringBuilder(dp[i][j]);
						dp[i+1][j*a[i+1]].append('*');
					} else {
						StringBuilder sb = new StringBuilder();
						sb.append(dp[i][j]).append('*');
						if (sb.toString().compareTo(dp[i+1][j*a[i+1]].toString()) > 0) {
							dp[i+1][j*a[i+1]] = sb;
						}
					}
				}
			}
		}

		out.println(dp[n-1][t]);
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		dump((end-start) + "ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}
0