結果

問題 No.2970 三次関数の絶対値
ユーザー kakel-san
提出日時 2024-11-29 22:01:58
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,786 bytes
コンパイル時間 10,056 ms
コンパイル使用メモリ 164,640 KB
実行使用メモリ 190,540 KB
最終ジャッジ日時 2024-11-29 22:02:15
合計ジャッジ時間 15,035 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (104 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]);
WriteLine(Abs(c, l, r));
}
static double Abs(int[] c, int l, int r)
{
var list = new List<double>();
list.Add(FD(c, l));
list.Add(FD(c, r));
if (c[3] != 0)
{
var rt = 4 * c[2] * c[2] - 12 * c[1] * c[3];
if (rt == 0)
{
var x = -c[2] / 3.0 / c[3];
if (x >= l && x <= r) list.Add(FD(c, x));
}
else if (rt > 0)
{
var sq = Math.Sqrt(rt);
var x1 = (-2 * c[2] + sq) / 6 / c[3];
if (x1 >= l && x1 <= r) list.Add(FD(c, x1));
var x2 = -(2 * c[2] + sq) / 6 / c[3];
if (x2 >= l && x2 <= r) list.Add(FD(c, x2));
}
}
else if (c[2] != 0)
{
var x = - c[1] / 2.0 / c[2];
if (x >= l && x <= r) list.Add(FD(c, x));
}
list.Sort();
if (list[0] < 0 && list[^1] > 0) return 0;
else return 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;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0