結果

問題 No.955 ax^2+bx+c=0
ユーザー drymouse
提出日時 2020-01-01 23:41:28
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,701 bytes
コンパイル時間 512 ms
コンパイル使用メモリ 32,384 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-22 17:24:31
合計ジャッジ時間 2,676 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 77 WA * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void logging(int n, double x1, double x2) {
    printf("%d\n", n);
    if (n == 1) {
        printf("%.15lf\n", x1);
    } else if (n == 2) {
        printf("%.15lf\n%.15lf\n", x1, x2);
    }
    
    exit(EXIT_SUCCESS);
}

int main(void) {
    long a, b, c;
    double s1, s2;
    long long D;
    scanf("%ld%ld%ld", &a, &b, &c);
    if (a == 0) {
        if (b == 0) {
            if (c == 0) {
                logging(-1, 0, 0);
            }
            logging(0, 0, 0);
        }
        s1 = (double)-c/b;
        logging(1, s1, 0);
    }
    if (a == b && b == c) {
        logging(0, 0, 0);
    }
    if (b == 0) {
        if (c == 0) {
            logging(1, 0, 0);
        }
        s1 = sqrt(-(double)c/a);
        s2 = -s1;
        logging(2, s1, s2);
    }
    if (c == 0) {
        s1 = 0;
        s2 = -(double)b/a;
        if (s1 < s2) {
            logging(2, s1, s2);
        }
        logging(2, s2, s1);
    }

    if (b%2 == 0) {
        D = (long long)(b/2)*(b/2) - (long long)a*c;
        if (D > 0) {
            s1 = -(double)(b/2)/a - sqrt(D)/a;
            s2 = -(double)(b/2)/a + sqrt(D)/a;
            logging(2, s1, s2);
        } else if (D == 0) {
            s1 = (double)-b/a;
            logging(1, s1, 0);
        } else {
            logging(0, 0, 0);
        }
    }
    D = (long long)b*b - (long long)4*a*c;
    if (D > 0) {
        s1 = (double)-b/(2*a) - sqrt(D)/(2*a);
        s2 = (double)-b/(2*a) + sqrt(D)/(2*a);
        logging(2, s1, s2);
    } else if (D == 0) {
        s1 = (double)-b/(2*a);
        logging(1, s1, 0);
    } else {
        logging(0, 0, 0);
    }

    return EXIT_SUCCESS;
}
0