結果
| 問題 | No.10 +か×か |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-03-17 10:23:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 5,000 ms |
| コード長 | 653 bytes |
| 記録 | |
| コンパイル時間 | 458 ms |
| コンパイル使用メモリ | 62,848 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-06 14:34:28 |
| 合計ジャッジ時間 | 1,113 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 |
ソースコード
#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;
}