結果

問題 No.505 カードの数式2
ユーザー はまやんはまやん
提出日時 2017-04-21 22:53:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 762 bytes
コンパイル時間 2,059 ms
コンパイル使用メモリ 165,856 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-07-20 06:28:07
合計ジャッジ時間 4,846 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 TLE * 1
other -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




int N, A[101010];
//-----------------------------------------------------------------------------------
int sol(int f) {
    int a = A[0];

    rep(i, 0, N - 1) {
        int t = f % 4;
        f /= 4;

        if (A[i + 1] == 0 && t == 3) return -1;

        if (t == 0) a += A[i + 1];
        if (t == 1) a -= A[i + 1];
        if (t == 2) a *= A[i + 1];
        if (t == 3) a /= A[i + 1];
    }

    return a;
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> N;
    rep(i, 0, N) scanf("%d", &A[i]);

    int ans = 0;
    rep(flag, 0, 1 << ((N - 1) * 2)) ans = max(ans, sol(flag));
    printf("%d\n", ans);
}
0