結果
| 問題 | No.2970 三次関数の絶対値 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-29 21:53:40 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,496 bytes |
| 記録 | |
| コンパイル時間 | 8,429 ms |
| コンパイル使用メモリ | 165,696 KB |
| 実行使用メモリ | 185,408 KB |
| 最終ジャッジ日時 | 2024-11-29 21:53:54 |
| 合計ジャッジ時間 | 13,384 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 WA * 17 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /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/
ソースコード
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] * 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;
}
}