結果

問題 No.505 カードの数式2
ユーザー oxyshoweroxyshower
提出日時 2019-12-01 20:33:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 995 bytes
コンパイル時間 1,668 ms
コンパイル使用メモリ 167,364 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-08-13 23:07:40
合計ジャッジ時間 3,543 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  static int dp[21][2];
  for(int i = 0; i < n; i++){
    dp[i][0] = INF;
    dp[i][1] = -INF;
  }
  dp[0][0] = dp[0][1] = a[0];
  for(int i = 1; i < n; i++){
    dp[i][0] = min(dp[i][0], dp[i-1][0] + a[i]);
    dp[i][0] = min(dp[i][0], dp[i-1][0] - a[i]);
    dp[i][0] = min({dp[i][0], dp[i-1][0] * a[i], dp[i-1][1] * a[i]});
    if(a[i] != 0) dp[i][0] = min(dp[i][0], dp[i-1][0] / a[i]);
    dp[i][1] = max(dp[i][1], dp[i-1][1] + a[i]);
    dp[i][1] = max(dp[i][1], dp[i-1][0] - a[i]);
    dp[i][1] = max({dp[i][1], dp[i-1][1] * a[i], dp[i-1][0] * a[i]});
    if(a[i] != 0) dp[i][1] = max(dp[i][1], dp[i-1][1] / a[i]);
    //cout << dp[i][0] << " " << dp[i][1] << endl;
  }
  cout << max(dp[n-1][0], dp[n-1][1]) << endl;

  return 0;
}
0