結果
問題 |
No.505 カードの数式2
|
ユーザー |
![]() |
提出日時 | 2018-01-26 21:23:49 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 714 bytes |
コンパイル時間 | 1,639 ms |
コンパイル使用メモリ | 163,036 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-28 00:00:35 |
合計ジャッジ時間 | 3,004 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 WA * 17 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T> void chmin(T &a,T b){if(a>b) a=b;} template<typename T> void chmax(T &a,T b){if(a<b) a=b;} signed main(){ Int n; cin>>n; vector<Int> a(n); for(Int i=0;i<n;i++) cin>>a[i]; vector< vector<Int> > dp(2,vector<Int>(n+1,0)); auto check=[&](Int i,Int x){ chmin(dp[0][i+1],x); chmax(dp[1][i+1],x); }; for(Int i=0;i<n;i++){ check(i,dp[0][i]+a[i]); check(i,dp[0][i]-a[i]); check(i,dp[0][i]*a[i]); if(a[i]) check(i,dp[0][i]/a[i]); check(i,dp[1][i]+a[i]); check(i,dp[1][i]-a[i]); check(i,dp[1][i]*a[i]); if(a[i]) check(i,dp[1][i]/a[i]); } cout<<dp[1][n]<<endl; return 0; }