結果

問題 No.505 カードの数式2
ユーザー rodearodea
提出日時 2018-03-17 13:05:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 541 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 66,432 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-08-25 15:39:06
合計ジャッジ時間 2,875 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 RE -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 RE -
testcase_08 AC 2 ms
4,380 KB
testcase_09 RE -
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 RE -
testcase_14 AC 1 ms
4,380 KB
testcase_15 WA -
testcase_16 RE -
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 RE -
testcase_20 AC 2 ms
4,376 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int n, a[20];
	long dp[20];

	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}

	int add, sub, mul, div;
	add = a[1] + a[2];
	sub = a[1] - a[2];
	mul = a[1] * a[2];
	div = a[1] / a[2];

	dp[1] = max(max(add, sub), max(mul, div));

	for (int i = 1; i < n - 1; i++)
	{
		add = dp[i] + a[i + 2];
		sub = dp[i] - a[i + 2];
		mul = dp[i] * a[i + 2];
		div = dp[i] / a[i + 2];

		dp[i + 1] = max(max(add, sub), max(mul, div));
	}
	cout << dp[n - 1] << endl;
}
0