結果

問題 No.505 カードの数式2
ユーザー Ut.k
提出日時 2017-04-21 23:16:49
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 672 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 59,100 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 17:42:11
合計ジャッジ時間 3,813 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int DFS(int, const std::vector<int>&, int)’:
main.cpp:23:1: warning: control reaches end of non-void function [-Wreturn-type]
   23 | }
      | ^

ソースコード

diff #

#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(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(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)),
	       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;
}
0