結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
koukonko
|
| 提出日時 | 2015-12-13 03:24:13 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,129 bytes |
| コンパイル時間 | 2,319 ms |
| コンパイル使用メモリ | 77,556 KB |
| 実行使用メモリ | 84,496 KB |
| 最終ジャッジ日時 | 2024-09-15 11:03:11 |
| 合計ジャッジ時間 | 9,221 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 1 TLE * 1 -- * 7 |
ソースコード
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();
}
}
}
koukonko