結果

問題 No.10 +か×か
ユーザー koukonkokoukonko
提出日時 2015-12-13 03:24:13
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,129 bytes
コンパイル時間 1,979 ms
コンパイル使用メモリ 73,620 KB
実行使用メモリ 55,480 KB
最終ジャッジ日時 2023-10-13 14:15:52
合計ジャッジ時間 8,988 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,636 KB
testcase_01 AC 42 ms
49,332 KB
testcase_02 AC 41 ms
49,172 KB
testcase_03 WA -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
		try {
			int N = Integer.parseInt(read.readLine());
			int total = Integer.parseInt(read.readLine());
			boolean[] flag = new boolean[N - 1];

			String[] box = read.readLine().split(" ");
			int[] num = new int[N];

			for (int i = 0; i < N; ++i) {
				num[i] = Integer.parseInt(box[i]);
			}

			int count = (int) Math.pow(2, N - 1);
			for (int i = 0; i < count; ++i) {
				int pro = num[0];
				for (int j = 0; j < N - 1; ++j) {
					if (flag[j] == false) {
						pro += num[j + 1];
					} else {
						pro *= num[j + 1];
					}
				}
				if (total == pro) {
					for (int j = 0; j < N - 1; ++j) {
						if (flag[j] == false) {
							System.out.print('+');
						} else {
							System.out.print('*');
						}
					}
					break;
				} else {

					int s = 0;
					while (flag[s]) {
						flag[s] = false;
						++s;
					}
					flag[s] = true;

				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
0