結果
| 問題 |
No.505 カードの数式2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-04-21 22:39:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 699 bytes |
| コンパイル時間 | 717 ms |
| コンパイル使用メモリ | 71,344 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 05:30:52 |
| 合計ジャッジ時間 | 15,443 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 WA * 3 |
ソースコード
#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;
}