結果

問題 No.10 +か×か
ユーザー cielciel
提出日時 2014-11-17 16:08:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 431 ms / 5,000 ms
コード長 624 bytes
コンパイル時間 451 ms
コンパイル使用メモリ 59,960 KB
実行使用メモリ 27,032 KB
最終ジャッジ日時 2023-08-21 06:08:37
合計ジャッジ時間 1,961 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 217 ms
16,920 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 431 ms
27,032 KB
testcase_07 AC 137 ms
14,772 KB
testcase_08 AC 12 ms
4,376 KB
testcase_09 AC 19 ms
4,716 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
using namespace std;
set<pair<int,int> >se;
void dfs(int total,int cur,vector<int> &v,string s){
	if(s.size()==v.size()-1){
		if(cur==total){
			puts(s.c_str());
			exit(0);
		}
		return;
	}
	if(cur>total||se.find(make_pair(cur,s.size()))!=se.end())return;
	dfs(total,cur+v[s.size()+1],v,s+'+');
	dfs(total,cur*v[s.size()+1],v,s+'*');
	se.insert(make_pair(cur,s.size()));
}

int main(){
	int n,total;
	scanf("%d%d",&n,&total);
	vector<int>v(n);
	for(int i=0;i<n;i++)scanf("%d",&v[i]);
	dfs(total,v[0],v,"");
}
0