結果
問題 |
No.505 カードの数式2
|
ユーザー |
👑 |
提出日時 | 2022-09-24 12:04:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 623 bytes |
コンパイル時間 | 730 ms |
コンパイル使用メモリ | 66,248 KB |
最終ジャッジ日時 | 2025-02-07 14:15:32 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include <iostream> using namespace std; int main(){ int n;cin>>n; long long z;cin>>z; long long nwmx = z; long long nwmn = z; for(int i = 0; n-1 > i; i++){ long long x;cin>>x; long long nexmx = max(nwmx+x,nwmn+x); long long nexmn = min(nwmx+x,nwmn+x); nexmx = max(nexmx,max(nwmx-x,nwmn-x)); nexmn = min(nexmn,min(nwmx-x,nwmn-x)); nexmx = max(nexmx,max(nwmx*x,nwmn*x)); nexmn = min(nexmn,min(nwmx*x,nwmn*x)); if(x!=0){ nexmx = max(nexmx,max(nwmx/x,nwmn/x)); nexmn = min(nexmn,min(nwmx/x,nwmn/x)); } nwmx = nexmx; nwmn = nexmn; } cout << nwmx << endl; }