結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー masa
提出日時 2017-04-21 22:40:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 699 bytes
コンパイル時間 602 ms
コンパイル使用メモリ 71,452 KB
実行使用メモリ 13,764 KB
最終ジャッジ日時 2024-07-20 05:31:44
合計ジャッジ時間 5,268 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other AC * 1 WA * 4 TLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

const long long inf = 1e18;

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

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

	int limit = 1;
	for (int i = 0; i < n - 1; i++) {
		limit *= 3;
	}

	long long ans = -inf;
	for (int i = 0; i < limit; i++) {
		int tmp = i;
		long long x = a[0];
		for (int j = 1; j < n; j++) {
			int op = tmp % 3;

			switch (op) {
				case 0: x += a[j]; break;
				case 1: x -= a[j]; break;
				case 2: x *= a[j]; break;
				default: break;
			}

			tmp /= 3;
		}

		ans = max(ans, x);
	}
	cout << ans << endl;
	return 0;
}
0