結果

問題 No.3372 Suitable Constraint
コンテスト
ユーザー Tehom
提出日時 2026-02-05 16:39:13
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 1,026 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,400 ms
コンパイル使用メモリ 283,556 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-02-05 16:39:22
合計ジャッジ時間 7,697 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 5 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repl(i,a,b) for(ll i=(a);i<(b);i++)
#define all(a) (a).begin(),(a).end()

template <typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;} return false;}
template <typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;} return false;}


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

  int T; cin >> T;
  while(T--){
    int n; cin >> n;
    vector<ll> a(n);
    bool plus=false,minus=false;
    rep(i,0,n){
      cin >> a[i];
      if(a[i]>0) plus=true;
      if(a[i]<0) minus=true;
    }
    if(plus && minus){
      ll x=1e18,y=-1e18;
      rep(i,0,n){
        if(a[i]>0) chmin(x,a[i]);
        else if(a[i]<0) chmax(y,a[i]);
      }
      cout << x*y << '\n';
    }
    else if(plus){
      sort(all(a));
      cout << a[0]*a[1] << '\n';
    }
    else{
      sort(a.rbegin(),a.rend());
      cout << a[0]*a[1] << '\n';
    }
  }
}
0