結果

問題 No.505 カードの数式2
コンテスト
ユーザー okchan08
提出日時 2018-04-06 12:34:43
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,049 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 454 ms
コンパイル使用メモリ 76,912 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-09 20:31:19
合計ジャッジ時間 1,749 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/string:53,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/locale_classes.h:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ios_base.h:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ios:46,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
                 from main.cpp:1:
In function 'const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = long long int]',
    inlined from 'int main()' at main.cpp:34:31:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:239:7: warning: 'next' may be used uninitialized [-Wmaybe-uninitialized]
  239 |       if (__b < __a)
      |       ^~
main.cpp: In function 'int main()':
main.cpp:25:20: note: 'next' was declared here
   25 |                 ll next;
      |                    ^~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <climits>
#include <string>

using namespace std;
using ll = long long;

char op[] = {'*', '/', '+', '-'};


int main(){
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin >> A[i];

    ll tot_max = A[0];
    ll tot_min = A[0];

    for(int i=1;i<N;i++){
        ll next_max = LLONG_MIN;
        ll next_min = LLONG_MAX;
        for(auto cur : {tot_max, tot_min}){
            for(int j=0;j<4;j++){
                ll next;
                if(op[j] == '/' && A[i]==0) continue;
                switch(op[j]){
                    case '+' : next = cur + A[i]; break;
                    case '-' : next = cur - A[i]; break;
                    case '*' : next = cur * A[i]; break;
                    case '/' : next = cur / A[i]; break;
                }
                next_max = max(next_max, next);
                next_min = min(next_min, next);
            }
        }
        tot_max = next_max;
        tot_min = next_min;
    }
    cout << tot_max << endl;
    return 0;
}
0