結果
問題 | No.505 カードの数式2 |
ユーザー |
![]() |
提出日時 | 2017-04-21 22:46:40 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,277 bytes |
コンパイル時間 | 1,210 ms |
コンパイル使用メモリ | 159,932 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-14 07:13:46 |
合計ジャッジ時間 | 2,073 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define all(v) (v).begin(),(v).end() #define fi first #define se second typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;} template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;} int N; int A[22]; int ma[22],mi[22]; signed main(){ cin>>N; rep(i,N)cin>>A[i]; fill_n(ma,22,LLONG_MIN); fill_n(mi,22,LLONG_MAX); ma[1]=A[0]; mi[1]=A[0]; for(int i=1;i<N;i++){ chmax(ma[i+1],ma[i]+A[i]); chmax(ma[i+1],ma[i]-A[i]); chmax(ma[i+1],ma[i]*A[i]); if(A[i])chmax(ma[i+1],ma[i]/A[i]); chmax(ma[i+1],mi[i]+A[i]); chmax(ma[i+1],mi[i]-A[i]); chmax(ma[i+1],mi[i]*A[i]); if(A[i])chmax(ma[i+1],mi[i]/A[i]); chmin(mi[i+1],ma[i]+A[i]); chmin(mi[i+1],ma[i]-A[i]); chmin(mi[i+1],ma[i]*A[i]); if(A[i])chmin(mi[i+1],ma[i]/A[i]); chmin(mi[i+1],mi[i]+A[i]); chmin(mi[i+1],mi[i]-A[i]); chmin(mi[i+1],mi[i]*A[i]); if(A[i])chmin(mi[i+1],mi[i]/A[i]); } cout<<ma[N]<<endl; return 0; }