結果

問題 No.505 カードの数式2
ユーザー trineutron
提出日時 2020-07-26 21:07:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 706 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 197,488 KB
最終ジャッジ日時 2025-01-12 06:17:54
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    int64_t l = a.at(0), r = a.at(0);
    for (int i = 1; i < n; i++) {
        vector<int64_t> v;
        v.push_back(l + a.at(i));
        v.push_back(r + a.at(i));
        v.push_back(l - a.at(i));
        v.push_back(r - a.at(i));
        v.push_back(l * a.at(i));
        v.push_back(r * a.at(i));
        if (a.at(i)) {
            v.push_back(l / a.at(i));
            v.push_back(r / a.at(i));
        }
        l = *min_element(v.begin(), v.end());
        r = *max_element(v.begin(), v.end());
    }
    cout << r << endl;
}
0