結果
| 問題 |
No.505 カードの数式2
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2018-01-26 21:24:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 740 bytes |
| コンパイル時間 | 2,901 ms |
| コンパイル使用メモリ | 162,916 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-28 00:01:22 |
| 合計ジャッジ時間 | 3,395 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 WA * 7 |
ソースコード
#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));
dp[0][1]=dp[1][1]=a[0];
auto check=[&](Int i,Int x){
chmin(dp[0][i+1],x);
chmax(dp[1][i+1],x);
};
for(Int i=1;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;
}
beet