結果

問題 No.10 +か×か
ユーザー tempura-samatempura-sama
提出日時 2016-04-13 22:29:47
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 572 bytes
コンパイル時間 485 ms
コンパイル使用メモリ 53,872 KB
実行使用メモリ 10,144 KB
最終ジャッジ日時 2024-04-15 01:06:46
合計ジャッジ時間 6,863 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

#define N 50

int n;
int ans;
int v[N];
char op[N-1];

int dfs(char o, int l, int t)
{
	t = o == '+' ? (t + v[l + 1]) : (t * v[l + 1]);
	op[l] = o;
	if ( t > ans ) {
		return -1;
	}
	if ( l == n - 2 ) {
		return t == ans ? 1 : -1;
	}
	int x = dfs('+', l + 1, t);
	if ( x != 1 ) {
		x = dfs('*', l + 1, t);
	}
	return x;
}

int main()
{
	cin >> n;
	cin >> ans;
	for ( int i = 0; i < n; i++ ) {
		cin >> v[i];
	}

	dfs('+', 0, v[0]) <= 0 && dfs('*', 0, v[0]);

	for ( int i = 0; i < n - 1; i++ ) {
		cout << op[i];
	}

	return 0;
}
0