結果

問題 No.10 +か×か
ユーザー OnjuOnju
提出日時 2015-02-01 17:53:23
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 680 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 61,084 KB
実行使用メモリ 8,312 KB
最終ジャッジ日時 2023-09-05 09:32:35
合計ジャッジ時間 7,200 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 TLE -
testcase_04 -- -
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 = 1; j < N; ++j)
		{
			if (b[N - j])
				res *= A[j];
			else
				res += A[j];
			if (res > T)
				break;
		}

		if (res == T)
			break;
	}

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

	return 0;
}
0