結果

問題 No.10 +か×か
ユーザー NotationNap
提出日時 2015-04-22 04:53:55
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 596 bytes
コンパイル時間 1,392 ms
コンパイル使用メモリ 157,936 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-12-14 15:29:36
合計ジャッジ時間 1,788 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long Int;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))

int N;
int total;
int A[55];
char ops[55];

bool vis[55][100010];

void dfs(int d, int val) {
	if (d == N) {
		if (val == total) {
			throw 1;
		}
		return;
	}
	if (val > total) return;
	if (vis[d][val]) return;
	vis[d][val] = true;
	ops[d] = '+';
	dfs(d + 1, val + A[d]);
	ops[d] = '*';
	dfs(d + 1, val * A[d]);
}

int main() {
	cin >> N >> total;
	REP(i, N) cin >> A[i];
	try { dfs(1, A[0]); } catch (int e) {}
	for (int i = 1; i < N; i++) cout << ops[i]; cout << endl;
}
0