結果

問題 No.10 +か×か
ユーザー kaffelunkaffelun
提出日時 2017-10-04 22:57:42
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 759 bytes
コンパイル時間 3,135 ms
コンパイル使用メモリ 146,120 KB
実行使用メモリ 22,728 KB
最終ジャッジ日時 2023-08-10 12:51:58
合計ジャッジ時間 8,155 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int N, T;
int A[50];
int dp[50][100000];
vector<int> zeros;
int64_t ans;
int recursive(int pos, int val, int64_t oper) {
	int retval = 0;
	if(pos >= N) {
		if(val == T) {
			ans = oper;
			return 1;
		}
		return 0;
	}
	if(dp[pos][val]) return 0;
	if(val > T) return 0;
	retval = recursive(pos + 1, val + A[pos], oper) ||
		     recursive(pos + 1, val * A[pos], oper | (1 << pos));
	dp[pos][val] = retval;
	return retval;
}

int main() {
	cin >> N >> T;
	for(int i = 0; i < N; i++) {
		cin >> A[i];
		for(int j = 0; j < T; j++) {
			dp[i][j] = 0;
		}
		if(A[i] == 0) zeros.push_back(i);
	}
	recursive(1, A[0], 0);
	for(int i = 1; i < N; i++) {
		cout << (ans & (1 << i) ? "*" : "+");
	}
	cout << endl;
	return 0;
}
0