結果

問題 No.2970 三次関数の絶対値
ユーザー kakel-san
提出日時 2024-11-29 21:51:44
言語 C#
(.NET 8.0.404)
結果
WA  
実行時間 -
コード長 1,489 bytes
コンパイル時間 8,478 ms
コンパイル使用メモリ 169,140 KB
実行使用メモリ 187,316 KB
最終ジャッジ日時 2024-11-29 21:52:04
合計ジャッジ時間 13,526 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30 WA * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (101 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  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;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
    static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var p = NList;
        var (l, r) = (p[0], p[1]);
        var list = new List<double>();
        list.Add(FD(c, l));
        list.Add(FD(c, r));
        if (c[3] != 0)
        {
            var rt = 4 * c[2] - 12 * c[1] * c[3];
            if (rt == 0)
            {
                list.Add(FD(c, -c[2] / 3.0 / c[3]));
            }
            else if (rt > 0)
            {
                var sq = Math.Sqrt(rt);
                list.Add(FD(c, (-2 * c[2] + sq) / 6 / c[3]));
                list.Add(FD(c, -(2 * c[2] + sq) / 6 / c[3]));
            }
        }
        else if (c[2] != 0)
        {
            list.Add(FD(c, - c[1] / 2.0 / c[2]));
        }
        list.Sort();
        if (list[0] < 0 && list[^1] > 0) WriteLine(0);
        else WriteLine(list.Select(Math.Abs).Min());
    }
    static double FD(int[] c, double x)
    {
        return c[0] + c[1] * x + c[2] * x * x + c[3] * x * x * x;
    }
}
0