結果
| 問題 |
No.505 カードの数式2
|
| コンテスト | |
| ユーザー |
toho_cake
|
| 提出日時 | 2017-04-22 10:02:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 582 bytes |
| コンパイル時間 | 596 ms |
| コンパイル使用メモリ | 57,384 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-21 16:02:28 |
| 合計ジャッジ時間 | 2,855 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 5 RE * 10 |
ソースコード
#include <iostream>
#include <algorithm>
#define INF 114514191
using namespace std;
int N, a[20], dp[20];
int rec(int idx) {
if(idx == 0) return a[0];
if(dp[idx] != -INF) return dp[idx];
int ret = -INF;
int res = rec(idx - 1);
if(res != 0) {
ret = res / a[idx];
}
ret = max(ret, res + a[idx]);
ret = max(ret, res - a[idx]);
ret = max(ret, res * a[idx]);
return dp[idx] = ret;
}
int main() {
cin >> N;
for(int i = 0; i < N; i++) {
cin >> a[i];
}
fill_n(dp, 20, -INF);
cout << rec(N - 1) << endl;
}
toho_cake