結果

問題 No.505 カードの数式2
ユーザー vjudge1
提出日時 2025-06-28 14:48:02
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 635 bytes
コンパイル時間 3,256 ms
コンパイル使用メモリ 275,820 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-28 14:48:07
合計ジャッジ時間 3,970 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,x,a[2],b[2];
signed main() 
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    cin>>n>>x;
    a[0]=a[1]=x;
    for(int i=1;i<n;i++)
    {
        cin>>x;
        b[0]=LLONG_MIN,b[1]=LLONG_MAX;
        b[0]=max({b[0],a[0]+x,a[0]-x,a[0]*x,a[1]+x,a[1]-x,a[1]*x});
        b[1]=min({b[0],a[0]+x,a[0]-x,a[0]*x,a[1]+x,a[1]-x,a[1]*x});
        if(x!=0)
        {
            b[0]=max({b[0],a[0]/x,a[1]/x});
            b[1]=min({b[1],a[0]/x,a[1]/x});
        }
        a[0]=b[0];
        a[1]=b[1];
    }
    cout<<max(a[0],a[1]);
    return 0;
}
0