結果

問題 No.3372 Suitable Constraint
コンテスト
ユーザー The Forsaking
提出日時 2025-12-04 14:17:22
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 681 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,656 ms
コンパイル使用メモリ 196,272 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-12-04 14:17:27
合計ジャッジ時間 5,052 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |     scanf("%d", &T);
      |     ~~~~~^~~~~~~~~~
main.cpp:28:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
main.cpp:29:46: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |         for (int i = 1; i < n + 1; i++) scanf("%d", w + i);
      |                                         ~~~~~^~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
const int N = 2000010, MOD = 998244353, INF = 0x3f3f3f3f;
int n, m, w[N];


void solve() {
    sort(w + 1, w + n + 1);
    if (w[1] >= 0 || w[n] <= 0) {
        printf("%lld\n", (ll)w[1] * w[n]);
    } else {
        for (int i = 2; i < n + 1; i++)
            if (w[i] >= 0 && w[i - 1] <= 0) {
                printf("%lld\n", w[i] * (ll)w[i - 1]);
                return;
            }
    }
}

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        scanf("%d", &n);
        for (int i = 1; i < n + 1; i++) scanf("%d", w + i);
        solve();
    }
    return 0;
}
0