結果

問題 No.3372 Suitable Constraint
コンテスト
ユーザー kakel-san
提出日時 2025-11-21 21:27:41
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,594 bytes
コンパイル時間 8,142 ms
コンパイル使用メモリ 169,688 KB
実行使用メモリ 196,932 KB
最終ジャッジ日時 2025-11-21 21:27:55
合計ジャッジ時間 10,568 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (109 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics.X86;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var t = NN;
        var ans = new long[t];
        for (var u = 0; u < t; ++u)
        {
            var n = NN;
            var a = NList;
            ans[u] = Const(n, a);
        }
        WriteLine(string.Join("\n", ans));
    }
    static long Const(int n, int[] a)
    {
        var pmax = long.MinValue;
        var pmin = long.MaxValue;
        var mmax = long.MinValue;
        var mmin = long.MaxValue;
        foreach (var ai in a)
        {
            if (ai == 0) return 0;
            if (ai > 0)
            {
                pmax = Math.Max(pmax, ai);
                pmin = Math.Min(pmin, ai);
            }
            else
            {
                mmax = Math.Max(mmax, ai);
                mmin = Math.Min(mmin, ai);
            }
        }
        if (pmax > 0 && mmin < 0)
        {
            return pmin * mmax;
        }
        else if (pmax > 0)
        {
            return pmax * pmin;
        }
        else
        {
            return mmax * mmin;
        }
    }
}
0