結果

問題 No.10 +か×か
ユーザー tsukiotsukio
提出日時 2016-03-17 10:23:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 653 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 53,144 KB
実行使用メモリ 5,852 KB
最終ジャッジ日時 2023-08-21 06:18:06
合計ジャッジ時間 1,096 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 7 ms
5,632 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 9 ms
5,852 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,552 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0