結果

問題 No.505 カードの数式2
ユーザー pekempey
提出日時 2017-04-21 22:28:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 534 bytes
コンパイル時間 590 ms
コンパイル使用メモリ 71,508 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 05:25:04
合計ジャッジ時間 1,564 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 WA * 11
権限があれば一括ダウンロードができます

ソースコード

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