結果
| 問題 | No.3372 Suitable Constraint |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-11 02:34:49 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 1,195 bytes |
| 記録 | |
| コンパイル時間 | 1,654 ms |
| コンパイル使用メモリ | 214,648 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-02-11 02:34:54 |
| 合計ジャッジ時間 | 3,834 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
vector<long long> A(N);
for (int i = 0; i < N; i++) cin >> A[i];
bool hasZero = false;
bool hasPos = false, hasNeg = false;
long long minA = LLONG_MAX, maxA = LLONG_MIN;
long long minPos = LLONG_MAX; // smallest positive
long long maxNeg = LLONG_MIN; // largest negative (closest to 0)
for (long long x : A) {
if (x == 0) hasZero = true;
if (x > 0) {
hasPos = true;
minPos = min(minPos, x);
}
if (x < 0) {
hasNeg = true;
maxNeg = max(maxNeg, x);
}
minA = min(minA, x);
maxA = max(maxA, x);
}
long long ans;
if (hasZero) {
ans = 0;
} else if (!hasPos || !hasNeg) {
// all same sign
ans = minA * maxA;
} else {
ans = minPos * maxNeg;
}
cout << ans << '\n';
}
return 0;
}