結果
| 問題 |
No.505 カードの数式2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-04-21 23:59:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 618 bytes |
| コンパイル時間 | 676 ms |
| コンパイル使用メモリ | 61,188 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-21 06:10:50 |
| 合計ジャッジ時間 | 2,515 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 10 |
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
long N;
long DFS(long x, const vector<long> &a, long i) {
if (i == N) {
return x;
}
if (a[i] > 0) {
return max(max(DFS(x + a[i], a, i + 1), DFS(x * a[i], a, i + 1)),
DFS(x / a[i], a, i + 1));
}
if (a[i] < 0) {
return max(max(DFS(x - a[i], a, i + 1), DFS(x * a[i], a, i + 1)),
DFS(x / a[i], a, i + 1));
}
return DFS(x + a[i], a, i + 1);
}
int main() {
cin >> N;
vector<long> a(N);
for (long i = 0; i < N; i++) {
cin >> a[i];
}
cout << DFS(a[0], a, 1) << endl;;
return 0;
}