結果

問題 No.955 ax^2+bx+c=0
コンテスト
ユーザー kakel-san
提出日時 2025-12-24 23:26:37
言語 C#
(.NET 8.0.404)
結果
WA  
実行時間 -
コード長 2,424 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 15,731 ms
コンパイル使用メモリ 171,036 KB
実行使用メモリ 189,616 KB
最終ジャッジ日時 2025-12-24 23:27:04
合計ジャッジ時間 21,665 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 102 WA * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (90 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #
raw source code

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.Intrinsics.Arm;

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 p = NList;
        var (a, b, c) = (p[0], p[1], p[2]);
        if (a == 0)
        {
            if (b == 0)
            {
                if (c == 0) WriteLine(-1);
                else WriteLine(0);
            }
            else
            {
                WriteLine(1);
                WriteLine(- (double)c / b);
            }
        }
        else
        {
            var root = (long)b * b - 4L * a * c;
            if (root < 0)
            {
                WriteLine(0);
            }
            else if (root == 0)
            {
                WriteLine(1);
                WriteLine(- b / 2.0 / a);
            }
            else
            {
                var d = new System.Numerics.BigInteger(1_000_000_000_000);
                var first = -d * b;
                var second = d * d * root;
                var ng = System.Numerics.BigInteger.Zero;
                var ok = d * root;
                while (ok - ng > 1)
                {
                    var mid = (ok + ng) / 2;
                    if (mid * mid >= second) ok = mid;
                    else ng = mid;
                }
                WriteLine(2);
                var ans1 = (first - ok) / 2 / a;
                var ans2 = (first + ok) / 2 / a;
                if (ans1 < 0)
                {
                    ans1 = -ans1;
                    WriteLine($"-{ans1 / d}.{ans1 % d :000000000000}");
                }
                else
                {
                    WriteLine($"{ans1 / d}.{ans1 % d :000000000000}");
                }
                if (ans2 < 0)
                {
                    ans2 = -ans2;
                    WriteLine($"-{ans2 / d}.{ans2 % d :000000000000}");
                }
                else
                {
                    WriteLine($"{ans2 / d}.{ans2 % d :000000000000}");
                }
            }
        }
    }

}
0