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