結果

問題 No.10 +か×か
ユーザー kaffelunkaffelun
提出日時 2017-10-04 22:54:19
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 719 bytes
コンパイル時間 1,318 ms
コンパイル使用メモリ 146,296 KB
実行使用メモリ 22,824 KB
最終ジャッジ日時 2023-08-10 12:51:35
合計ジャッジ時間 4,409 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int recursive(int, int, int64_t)’:
main.cpp:19:9: warning: control reaches end of non-void function [-Wreturn-type]
  retval = recursive(pos + 1, val + A[pos], oper) ||
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        recursive(pos + 1, val * A[pos], oper | (1 << pos));
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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));
}

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