結果

問題 No.505 カードの数式2
ユーザー
提出日時 2020-12-23 19:42:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 939 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 94,136 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-21 16:29:45
合計ジャッジ時間 1,898 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long a[20];
	long long m[20], m1[20];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	m[0] = a[0], m1[0] = a[0];
	for (int i = 1; i < n; i++) {
		long long b1 = m[i - 1] + a[i];
		long long b2 = m[i - 1] - a[i];
		long long b3 = m[i - 1] * a[i];
		long long b4 = 0;
		if (a[i] != 0) {
			b4 = m[i - 1] / a[i];
		}
		long long b5 = m1[i - 1] + a[i];
		long long b6 = m1[i - 1] - a[i];
		long long b7 = m1[i - 1] * a[i];
		long long b8 = 0;
		if (a[i] != 0) {
			b8 = m1[i - 1] / a[i];
		}
		m[i] = max({ b1,b2,b3,b4,b5,b6,b7,b8 });
		m1[i] = min({ b1,b2,b3,b4,b5,b6,b7,b8 });
		
	}
	cout << m[n - 1] << endl;
}

0