結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-03-17 10:23:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 5,000 ms |
| コード長 | 653 bytes |
| コンパイル時間 | 473 ms |
| コンパイル使用メモリ | 55,640 KB |
| 実行使用メモリ | 6,016 KB |
| 最終ジャッジ日時 | 2024-12-14 15:35:17 |
| 合計ジャッジ時間 | 988 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#include <iostream>
#include <string>
using namespace std;
int n;
int t;
int nums[50];
char op[50];
bool visited[50][100001];
void Calc(int current, int value) {
if (value > t)
return;
if (current == n) {
if (value < t)
return;
op[n - 1] = '\0';
cout << string(op) << endl;
exit(0);
}
if (visited[current][value])
return;
visited[current][value] = true;
int op_index = current - 1;
op[op_index] = '+';
Calc(current + 1, value + nums[current]);
op[op_index] = '*';
Calc(current + 1, value * nums[current]);
}
int main() {
cin >> n >> t;
for (int i = 0; i < n; i++) {
cin >> nums[i];
}
Calc(1, nums[0]);
return 0;
}