結果

問題 No.505 カードの数式2
ユーザー pekempeypekempey
提出日時 2017-04-21 22:28:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 534 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 71,672 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-27 11:18:07
合計ジャッジ時間 1,642 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

int main() {
	int n;
	std::cin >> n;

	std::vector<int> a(n);
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}

	long long ans = -1e18;
	for (int i = 0; i < 1 << n - 1; i++) {
		long long val = a[0];
		for (int j = 0; j < n - 1; j++) {
			if (i >> j & 1) {
				if (a[j + 1] >= 0) {
					val += a[j + 1];
				} else {
					val -= a[j + 1];
				}
			} else {
				val *= a[j + 1];
			}
		}
		ans = std::max(ans, val);
	}
	std::cout << ans << std::endl;
}
0