結果

問題 No.505 カードの数式2
ユーザー Kmcode1Kmcode1
提出日時 2017-04-21 23:03:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 983 bytes
コンパイル時間 1,542 ms
コンパイル使用メモリ 151,540 KB
実行使用メモリ 14,860 KB
最終ジャッジ日時 2023-08-09 02:02:12
合計ジャッジ時間 2,721 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 5 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 33 ms
14,860 KB
testcase_22 AC 10 ms
7,144 KB
testcase_23 AC 12 ms
6,816 KB
testcase_24 AC 20 ms
12,032 KB
testcase_25 AC 16 ms
8,136 KB
testcase_26 AC 6 ms
5,344 KB
testcase_27 AC 7 ms
5,432 KB
testcase_28 AC 5 ms
4,384 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 6 ms
5,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;

#define MAX 17

vector<int> v;

vector<long long int> s[MAX];

int main(){
	int way = 1;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		v.push_back(a);
	}
	int bet = n - 1;
	s[0].push_back(v[0]);
	for (int i = 0; i < bet; i++){
		sort(s[i].begin(), s[i].end());
		for (int j = 0; j < s[i].size(); j++){
			if (j>0 && j + 1 < s[i].size()&&s[i][j]!=0&&s[i][j+1]!=0&&s[i][j-1]!=0){
				long long int ty = s[i][j] / abs(s[i][j]);
				long long int ty1 = s[i][j - 1] / abs(s[i][j - 1]);
				long long int ty2 = s[i][j + 1] / abs(s[i][j + 1]);
				if (ty == ty1&&ty == ty2)continue;
			}
			s[i + 1].push_back(s[i][j] * v[i + 1]);
			if(v[i+1]!=0)s[i + 1].push_back(s[i][j] / v[i + 1]);
			s[i + 1].push_back(s[i][j] + v[i + 1]);
			s[i + 1].push_back(s[i][j] - v[i + 1]);
		}
	}
	sort(s[bet].begin(), s[bet].end());
	printf("%lld\n", s[bet].back());
	return 0;
}
0