結果

問題 No.505 カードの数式2
コンテスト
ユーザー ei1333333
提出日時 2017-04-21 22:41:58
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
(最新)
TLE  
(最初)
実行時間 1,184 ms / 2,000 ms
コード長 653 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 837 ms
コンパイル使用メモリ 179,856 KB
実行使用メモリ 187,828 KB
最終ジャッジ日時 2026-04-02 21:03:23
合計ジャッジ時間 11,394 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

#include <bits/stdc++.h>

using namespace std;

typedef long long int64;
const int64 INF = 1LL << 58;


int N, A[16];

int64 createArray(int idx, int sz, int64 val)
{
  if(idx == sz) return (val);
  int64 ret = -INF;
  ret = max(ret, createArray(idx + 1, sz, val + A[idx]));
  ret = max(ret, createArray(idx + 1, sz, val - A[idx]));
  ret = max(ret, createArray(idx + 1, sz, val * A[idx]));
  if(A[idx] != 0) ret = max(ret, createArray(idx + 1, sz, val / A[idx]));
  return (ret);
}

int main()
{
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cout << createArray(1, N, A[0]) << endl;
}
0