結果

問題 No.3372 Suitable Constraint
コンテスト
ユーザー 👑 loop0919
提出日時 2025-10-18 12:16:44
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 2,596 ms
コンパイル使用メモリ 281,252 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-21 20:50:59
合計ジャッジ時間 4,074 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;

void solve() {
    int N;
    cin >> N;

    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    vector<ll> plus, minus;
    for (ll a: A) {
        if (a >= 0) plus.push_back(a);
        if (a <= 0) minus.push_back(a);
    }

    if (plus.size() == 0 || minus.size() == 0) {
        ll min_a = *min_element(A.begin(), A.end());
        ll max_a = *max_element(A.begin(), A.end());

        cout << min_a * max_a << "\n";
    } else {
        ll min_plus = *min_element(plus.begin(), plus.end());
        ll max_minus = *max_element(minus.begin(), minus.end());

        cout << min_plus * max_minus << "\n";
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int T;
    cin >> T;

    while (T--) solve();
}
0