結果

問題 No.505 カードの数式2
ユーザー myantamyanta
提出日時 2017-04-21 23:19:32
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 719 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 26,964 KB
実行使用メモリ 7,144 KB
最終ジャッジ日時 2023-09-27 23:19:37
合計ジャッジ時間 3,764 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>


typedef long long ll;


void max_u(ll& d, ll v)
{
	if(d<v) d=v;
}


void min_u(ll& d, ll v)
{
	if(d>v) d=v;
}


void solve_r(ll& result, ll v, int a[], int d, int n)
{
	if(d>=n)
	{
		max_u(result, v);
		return;
	}

	solve_r(result, v+a[d], a, d+1, n);
	solve_r(result, v-a[d], a, d+1, n);
	solve_r(result, v*a[d], a, d+1, n);
	if(a[d]) solve_r(result, v/a[d], a, d+1, n);
}


ll solve(int a[], int n)
{
	ll result=0;
	int i;

	for(i=0;i<n;i++) result+=a[i];
	solve_r(result, a[0], a, 1, n);
	return result;
}


int main(void)
{
	int n, a[16];
	int i;

	while(scanf("%d", &n)==1)
	{
		for(i=0;i<n;i++)
		{
			scanf("%d", &a[i]);
		}
		printf("%lld\n", solve(a, n));
	}

	return 0;
}
0