結果

問題 No.550 夏休みの思い出(1)
ユーザー RisenRisen
提出日時 2017-07-29 04:07:26
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,588 bytes
コンパイル時間 816 ms
コンパイル使用メモリ 111,660 KB
実行使用メモリ 20,992 KB
最終ジャッジ日時 2024-04-19 13:16:28
合計ジャッジ時間 4,413 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
20,736 KB
testcase_01 AC 41 ms
20,352 KB
testcase_02 AC 42 ms
20,352 KB
testcase_03 AC 42 ms
20,736 KB
testcase_04 AC 40 ms
20,864 KB
testcase_05 AC 44 ms
20,736 KB
testcase_06 AC 40 ms
20,736 KB
testcase_07 AC 39 ms
20,736 KB
testcase_08 AC 40 ms
20,480 KB
testcase_09 AC 42 ms
20,864 KB
testcase_10 AC 43 ms
20,992 KB
testcase_11 AC 40 ms
20,736 KB
testcase_12 AC 40 ms
20,480 KB
testcase_13 AC 39 ms
20,992 KB
testcase_14 AC 40 ms
20,352 KB
testcase_15 AC 42 ms
20,736 KB
testcase_16 AC 43 ms
20,736 KB
testcase_17 AC 43 ms
20,608 KB
testcase_18 AC 42 ms
20,736 KB
testcase_19 AC 41 ms
20,736 KB
testcase_20 AC 41 ms
20,736 KB
testcase_21 AC 41 ms
20,608 KB
testcase_22 AC 42 ms
20,736 KB
testcase_23 AC 44 ms
20,736 KB
testcase_24 AC 44 ms
20,608 KB
testcase_25 AC 41 ms
20,608 KB
testcase_26 AC 41 ms
20,480 KB
testcase_27 AC 41 ms
20,736 KB
testcase_28 AC 41 ms
20,736 KB
testcase_29 AC 40 ms
20,736 KB
testcase_30 AC 41 ms
20,608 KB
testcase_31 AC 39 ms
20,608 KB
testcase_32 AC 40 ms
20,736 KB
testcase_33 AC 41 ms
20,736 KB
testcase_34 AC 45 ms
20,864 KB
testcase_35 AC 43 ms
20,736 KB
testcase_36 AC 40 ms
20,864 KB
testcase_37 AC 40 ms
20,736 KB
testcase_38 AC 40 ms
20,736 KB
testcase_39 AC 42 ms
20,608 KB
testcase_40 AC 41 ms
20,736 KB
testcase_41 AC 41 ms
20,480 KB
testcase_42 AC 41 ms
20,736 KB
testcase_43 AC 39 ms
20,736 KB
testcase_44 AC 39 ms
20,736 KB
testcase_45 AC 42 ms
20,480 KB
testcase_46 AC 43 ms
20,736 KB
testcase_47 AC 41 ms
20,480 KB
testcase_48 AC 42 ms
20,608 KB
testcase_49 AC 40 ms
20,736 KB
testcase_50 AC 39 ms
20,736 KB
testcase_51 AC 40 ms
20,864 KB
testcase_52 AC 40 ms
20,736 KB
testcase_53 AC 39 ms
20,864 KB
testcase_54 AC 40 ms
20,736 KB
testcase_55 AC 43 ms
20,736 KB
testcase_56 AC 39 ms
20,736 KB
testcase_57 AC 39 ms
20,608 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Numerics;
using System.Linq;

class Solution
{
    // ビエタの解
    static double[] Solve(BigInteger a, BigInteger b, BigInteger c)
    {
        var p = (double)(3 * b - a * a) / 9;
        var t = 2 * a * a * a - 9 * a * b + 27 * c;
        var q = (double)t / 54;
        try
        {
            q = (double)((decimal)t / 54);
        }
        catch (OverflowException)
        {
        }

        var lamda = 2 * Math.Sqrt(-p);
        var theta = Math.Acos(-q / Math.Sqrt(-p * p * p)) / 3;
        var gamma = (double)a / 3;
        var x = new double[3];
        x[0] = lamda * Math.Cos(theta + 2 * Math.PI / 3) - gamma;
        x[1] = lamda * Math.Cos(theta - 2 * Math.PI / 3) - gamma;
        x[2] = lamda * Math.Cos(theta) - gamma;
        return x;
    }

    static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(BigInteger.Parse).ToArray();
        var a = vals[0];
        var b = vals[1];
        var c = vals[2];

        var xs = Solve(a, b, c).Distinct().Select(d => new BigInteger(Math.Round(d))).ToList();

        // 計算誤差対策のため,チェック
        foreach (var x in xs.ToList())
        {
            if (x * x * x + a * x * x + b * x + c != 0)
            {
                xs.Remove(x);
            }
        }

        // 1ミスのみ救済 (手抜き)
        if (xs.Count == 2)
        {
            // C == −αβγ より
            var x = -c / xs[0] / xs[1];
            xs.Add(x);
            xs.Sort();
        }

        Console.WriteLine(string.Join(" ", xs));
    }
}
0