結果

問題 No.505 カードの数式2
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-21 22:53:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 762 bytes
コンパイル時間 1,520 ms
コンパイル使用メモリ 163,384 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-27 12:20:46
合計ジャッジ時間 5,009 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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