結果

問題 No.505 カードの数式2
ユーザー uchiiiiuchiiii
提出日時 2020-08-20 12:10:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,828 bytes
コンパイル時間 3,145 ms
コンパイル使用メモリ 220,556 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-03 08:29:54
合計ジャッジ時間 4,492 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>inline int popcount(T a) {return __builtin_popcount(a);}
template<class T>inline T emod(T a, T p) { return (a%p + p) % p;}
//-------------------
int a[20];
int n;

ll bfs() {
    ll mx = 0;
    queue<PLL> q;
    q.push({0, 0});
    while(!q.empty()) {
        auto [k, v] = q.front(); q.pop();
        if(k == n) chmax(mx, v);
        else {
            q.push({k+1, v+a[k]});
            q.push({k+1, v-a[k]});
            q.push({k+1, v*a[k]});
        }
    }
    return mx;
}

ll dp[20][2];
int main() {
    cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15);
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }

    dp[0][0] = a[0];
    dp[0][1] = a[0];
    FOR(i,1,n-1) {
        rep(j, 2) {
            chmin(dp[i][0], dp[i-1][j] + a[i]);
            chmin(dp[i][0], dp[i-1][j] - a[i]);
            chmin(dp[i][0], dp[i-1][j] * a[i]);
        }
        rep(j, 2) {
            chmax(dp[i][1], dp[i-1][j] + a[i]);
            chmax(dp[i][1], dp[i-1][j] - a[i]);
            chmax(dp[i][1], dp[i-1][j] * a[i]);
        }
    }
    cout << dp[n-1][1] << endl;
    return 0;
}
0