結果

問題 No.3372 Suitable Constraint
コンテスト
ユーザー Tyto alba
提出日時 2025-11-23 09:28:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 81,452 KB
実行使用メモリ 7,840 KB
最終ジャッジ日時 2025-11-23 09:28:15
合計ジャッジ時間 3,487 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int t, n, tp, i, j;
    vector<int> a;
    long long ans;

    cin >> t;

    for (i=0; i<t; i++){
        cin >> n;
        a.clear();

        for(j=0; j<n; j++){
            cin >> tp;
            a.push_back(tp);
        }

        sort(a.begin(), a.end());
        if (find(a.begin(), a.end(), 0) != a.end()) ans = 0LL;
        else{
            ans = (long long) a.front() * a.back();
            if (ans < 0){
                auto it = upper_bound(a.begin(), a.end(), 0);
                ans = (long long) *it * *(it -1);
            }
        }

        cout << ans << "\n";

    }

    return 0;
}
0