結果
| 問題 |
No.505 カードの数式2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-24 10:29:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 836 bytes |
| コンパイル時間 | 1,783 ms |
| コンパイル使用メモリ | 200,412 KB |
| 最終ジャッジ日時 | 2025-01-14 20:01:08 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
REP (i, n) cin >> a[i];
vector<vector<long long>> dp(n, vector<long long>(2));
dp[0][0] = dp[0][1] = a[0];
for (int i = 1; i < n; i++) {
vector<long long> v;
v.push_back(dp[i-1][0] + a[i]);
v.push_back(dp[i-1][1] + a[i]);
v.push_back(dp[i-1][0] - a[i]);
v.push_back(dp[i-1][1] - a[i]);
v.push_back(dp[i-1][0] * a[i]);
v.push_back(dp[i-1][1] * a[i]);
if (a[i]) {
v.push_back(dp[i-1][0] / a[i]);
v.push_back(dp[i-1][1] / a[i]);
}
dp[i][0] = *min_element(v.begin(), v.end());
dp[i][1] = *max_element(v.begin(), v.end());
}
cout << dp[n-1][1] << endl;
return 0;
}