結果

問題 No.505 カードの数式2
ユーザー kimiyukikimiyuki
提出日時 2017-04-21 23:14:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,214 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 49,360 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 23:16:30
合計ジャッジ時間 1,643 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 WA -
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:20:20: 警告: ‘nxt’ may be used uninitialized [-Wmaybe-uninitialized]
   20 |                 ll nxt;
      |                    ^~~

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <limits>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
int main() {
    int n; scanf("%d", &n);
    vector<int> a(n); repeat (i,n) scanf("%d", &a[i]);
    ll cur_min = a[0];
    ll cur_max = a[0];
    repeat (i,n-1) {
        ll nxt_min = numeric_limits<ll>::max();
        ll nxt_max = numeric_limits<ll>::min();
        for (ll cur : { cur_min, cur_max }) {
            for (char op : "+-*/") {
                if (op == '/' and a[i+1] == 0) continue;
                ll nxt;
                switch (op) {
                    case '+': nxt = cur + a[i+1]; break;
                    case '-': nxt = cur - a[i+1]; break;
                    case '*': nxt = cur * a[i+1]; break;
                    case '/': nxt = cur + a[i+1]; break;
                }
                setmin(nxt_min, nxt);
                setmax(nxt_max, nxt);
            }
        }
        cur_min = nxt_min;
        cur_max = nxt_max;
    }
    printf("%lld\n", cur_max);
    return 0;
}
0