結果

問題 No.505 カードの数式2
ユーザー ukuku09ukuku09
提出日時 2017-04-21 22:31:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,049 bytes
コンパイル時間 2,438 ms
コンパイル使用メモリ 146,356 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-09-27 11:19:46
合計ジャッジ時間 3,296 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 71 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,384 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 71 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 71 ms
4,376 KB
testcase_31 AC 72 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int ans = 0;

int dfs(int idx, vint& a) {
  if(idx == a.size()-1) return a[idx];

  int res = -inf;
  rep(i, 3) {
    if(i == 0) {
      chmax(res, dfs(idx+1, a) + a[idx]);
    } else if(i == 1) {
      chmax(res, dfs(idx+1, a) - a[idx]);
    } else if(i == 2) {
      chmax(res, dfs(idx+1, a) * a[idx]);
    }
  }
  return res;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vint a(N);
  rep(i, N) cin >> a[i];
  reverse(all(a));
  cout << dfs(0, a) << endl;

  return 0;
}
0