結果

問題 No.10 +か×か
ユーザー btkbtk
提出日時 2015-05-03 18:10:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,499 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 85,620 KB
実行使用メモリ 4,452 KB
最終ジャッジ日時 2023-09-19 05:15:31
合計ジャッジ時間 2,294 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
#define LL long long
int N, M;
LL Total;
LL exist[100001];
LL a[100];

LL res1, res2;
void prev(int n,LL val,int bit){
	//cout << "prev:" << n << endl;
	if (n == M){
	//	cout << val << endl;
		if (exist[val] == -1 || bit < exist[val])
			exist[val] = bit;
		return;
	}
	if (val%a[n] == 0)prev(n - 1, val / a[n], bit + (1 << (n - M - 1)));
	if (val - a[n]>0)prev(n - 1, val - a[n], bit);
	return;
}


bool next(int n, LL val, int bit){

	//cout << "next:" << n << endl;
	if (n == M){
	//	cout << val << endl;
		if (exist[val] != -1){
			res1 = bit; res2 = exist[val];
			
			return true;
		}
		return false;
	}
	if (val + a[n+1] <= Total)if (next(n + 1, val+a[n+1], bit))return true;
	if (val*a[n+1] <= Total)if (next(n + 1, val*a[n+1], bit + (1 << n)))return true;

	return false;

}
int main(void){
	cin >> N >> Total;
	for (int i = 0; i <= 100000; i++)exist[i] = -1;
	for (int i = 0; i < N; i++)cin >> a[i];
	M = N / 2;
	prev(N - 1, Total, 0);
	next(0, a[0], 0);
	for (int i = 0; i < N/2; i++)
	{
		if (res1&(1 << i))cout << '*'; else cout << '+';
	}
	for (int i = 0; i < (N-1)/2; i++)
		if (res2&(1 << i))cout << '*'; else cout << '+';
	cout << endl;

	return 0;
}
0