結果

問題 No.505 カードの数式2
ユーザー Kmcode1
提出日時 2017-04-21 23:03:46
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 983 bytes
コンパイル時間 1,364 ms
コンパイル使用メモリ 166,256 KB
実行使用メモリ 14,692 KB
最終ジャッジ日時 2024-11-14 07:18:28
合計ジャッジ時間 2,396 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |                 scanf("%d", &a);
      |                 ~~~~~^~~~~~~~~~

ソースコード

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