結果

問題 No.505 カードの数式2
ユーザー masamasa
提出日時 2017-04-21 22:39:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 699 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 71,464 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 11:24:42
合計ジャッジ時間 16,651 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1,261 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 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,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 1,250 ms
4,376 KB
testcase_22 AC 1,340 ms
4,376 KB
testcase_23 AC 1,339 ms
4,376 KB
testcase_24 AC 1,266 ms
4,380 KB
testcase_25 AC 1,259 ms
4,380 KB
testcase_26 AC 1,277 ms
4,380 KB
testcase_27 AC 1,277 ms
4,380 KB
testcase_28 AC 1,264 ms
4,376 KB
testcase_29 WA -
testcase_30 AC 1,242 ms
4,380 KB
testcase_31 AC 1,247 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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