結果

問題 No.3372 Suitable Constraint
コンテスト
ユーザー ooaiu
提出日時 2025-11-27 16:30:34
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 3,062 ms
コンパイル使用メモリ 284,500 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-11-27 16:30:40
合計ジャッジ時間 5,553 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(),(x).end()
template<class T> ll MIN(const vector<T>&a) { return *min_element(all(a)); }
template<class T> ll MAX(const vector<T>&a) { return *max_element(all(a)); }
int main() {
	int tt;
	cin >> tt;
	while(tt--) {
		int N;
		cin >> N;
		vector<int>A(N);
		for(int i = 0; i < N; i++) cin >> A[i];
		vector<int>POS,NEG;
		bool f = false;
		for(int i = 0; i < N; i++) {
			if(A[i]==0)f=1;
			else if(A[i]<0)NEG.push_back(A[i]);
			else POS.push_back(A[i]);
		}
		vector<ll>th;
		if(f) {
			cout << 0 << "\n";
			continue;
		}
		if(NEG.size()&&POS.size())th.push_back(MIN(POS)*MAX(NEG));
		if(POS.size()>=2) th.push_back(MIN(POS)*MAX(POS));
		if(NEG.size()>=2) th.push_back(MIN(NEG)*MAX(NEG));
		assert(!th.empty());
		cout<<MIN(th)<<"\n";
	}
}
0