結果

問題 No.10 +か×か
ユーザー btkbtk
提出日時 2015-05-03 18:28:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 73 ms / 5,000 ms
コード長 1,751 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 85,932 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 06:12:26
合計ジャッジ時間 1,442 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 73 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 45 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 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;
inline int check(int a, int b){
	while (a != 0 || b != 0){
		if ((a & 1) != (b & 1))break;
		a >>= 1;
		b >>= 1;
	}
	return (a & 1) < (b & 1);


}
void prev(int n,LL val,int bit){
	//cout << "prev:" << n << endl;
	if (n == M){
	//	cout << val << endl;
		if (exist[val] == -1 || check(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];
			//cout << val << endl;
			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++)
	{
	//	cout << a[i];
		if (res1&(1 << i))cout << '*'; else cout << '+';
	}
	//cout << a[M] << endl;
	for (int i = 0; i < (N - 1) / 2; i++){

		if (res2&(1 << i))cout << '*'; else cout << '+';
//		cout << a[i + M + 1];
	}
	cout << endl;

	return 0;
}
0