結果

問題 No.10 +か×か
ユーザー OnjuOnju
提出日時 2015-02-01 17:44:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 684 bytes
コンパイル時間 614 ms
コンパイル使用メモリ 60,012 KB
実行使用メモリ 7,948 KB
最終ジャッジ日時 2023-09-05 09:31:57
合計ジャッジ時間 6,998 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//No.10 +か×か

//メモ
//  とりあえず素直に
//  TLEだったら計算量減らす

#include <iostream>
#include <bitset>
#include <cmath>
#define N_MAX 50

typedef long long LL;
using namespace std;

int main()
{
	const char* op = "+*";
	int N, T, A[N_MAX], res;
	LL p;
	bitset<64> b;

	cin >> N >> T;
	for (int i = 0; i < N; ++i)
		cin >> A[i];

	p = pow(2, N);

	//計算
	for (LL i = 0; i < p; ++i)
	{
		res = A[0];
		b = i;

		for (int j = 0; j < N - 1; ++j)
		{
			if (b[j])
				res *= A[j+1];
			else
				res += A[j+1];
			if (res > T)
				break;
		}

		if (res == T)
			break;
	}

	for (int i = 0; i < N - 1; ++i)
		cout << op[b[i]];
	cout << endl;

	return 0;
}
0