結果

問題 No.505 カードの数式2
ユーザー ukuku09
提出日時 2017-04-21 22:31:25
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,049 bytes
コンパイル時間 1,437 ms
コンパイル使用メモリ 160,320 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 05:26:29
合計ジャッジ時間 2,802 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}
using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;
const int inf = 1LL << 55;
const int mod = 1e9 + 7;
int ans = 0;
int dfs(int idx, vint& a) {
if(idx == a.size()-1) return a[idx];
int res = -inf;
rep(i, 3) {
if(i == 0) {
chmax(res, dfs(idx+1, a) + a[idx]);
} else if(i == 1) {
chmax(res, dfs(idx+1, a) - a[idx]);
} else if(i == 2) {
chmax(res, dfs(idx+1, a) * a[idx]);
}
}
return res;
}
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
int N;
cin >> N;
vint a(N);
rep(i, N) cin >> a[i];
reverse(all(a));
cout << dfs(0, a) << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0