結果

問題 No.955 ax^2+bx+c=0
ユーザー SuunnSuunn
提出日時 2020-05-07 07:52:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 5,859 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 76,488 KB
実行使用メモリ 50,068 KB
最終ジャッジ日時 2023-09-16 07:43:27
合計ジャッジ時間 11,851 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
34,000 KB
testcase_01 AC 38 ms
33,452 KB
testcase_02 AC 37 ms
33,880 KB
testcase_03 AC 37 ms
33,616 KB
testcase_04 AC 37 ms
33,988 KB
testcase_05 AC 44 ms
33,444 KB
testcase_06 AC 43 ms
49,468 KB
testcase_07 AC 44 ms
49,752 KB
testcase_08 AC 44 ms
49,424 KB
testcase_09 AC 44 ms
49,408 KB
testcase_10 AC 43 ms
49,448 KB
testcase_11 AC 43 ms
49,420 KB
testcase_12 AC 43 ms
49,424 KB
testcase_13 AC 42 ms
49,624 KB
testcase_14 AC 43 ms
49,520 KB
testcase_15 AC 43 ms
49,532 KB
testcase_16 AC 43 ms
49,348 KB
testcase_17 AC 44 ms
49,280 KB
testcase_18 AC 42 ms
49,400 KB
testcase_19 AC 46 ms
49,556 KB
testcase_20 AC 42 ms
49,396 KB
testcase_21 AC 42 ms
49,428 KB
testcase_22 AC 43 ms
49,544 KB
testcase_23 AC 42 ms
49,328 KB
testcase_24 AC 43 ms
49,284 KB
testcase_25 AC 43 ms
50,068 KB
testcase_26 AC 42 ms
49,568 KB
testcase_27 AC 43 ms
49,516 KB
testcase_28 AC 44 ms
49,356 KB
testcase_29 AC 42 ms
49,624 KB
testcase_30 AC 43 ms
49,284 KB
testcase_31 AC 43 ms
49,480 KB
testcase_32 AC 43 ms
49,360 KB
testcase_33 AC 42 ms
47,544 KB
testcase_34 AC 43 ms
49,480 KB
testcase_35 AC 42 ms
49,436 KB
testcase_36 AC 43 ms
49,760 KB
testcase_37 AC 43 ms
49,840 KB
testcase_38 AC 43 ms
49,436 KB
testcase_39 AC 43 ms
49,580 KB
testcase_40 AC 42 ms
49,828 KB
testcase_41 AC 43 ms
49,288 KB
testcase_42 AC 42 ms
49,828 KB
testcase_43 AC 42 ms
49,344 KB
testcase_44 AC 41 ms
49,464 KB
testcase_45 AC 41 ms
49,480 KB
testcase_46 AC 42 ms
49,532 KB
testcase_47 AC 42 ms
49,712 KB
testcase_48 AC 42 ms
49,528 KB
testcase_49 AC 42 ms
49,400 KB
testcase_50 AC 43 ms
49,532 KB
testcase_51 AC 43 ms
49,420 KB
testcase_52 AC 44 ms
49,476 KB
testcase_53 AC 42 ms
49,472 KB
testcase_54 AC 42 ms
49,288 KB
testcase_55 AC 41 ms
49,392 KB
testcase_56 AC 42 ms
49,532 KB
testcase_57 AC 43 ms
49,320 KB
testcase_58 AC 43 ms
49,284 KB
testcase_59 AC 42 ms
49,540 KB
testcase_60 AC 41 ms
49,568 KB
testcase_61 AC 41 ms
49,552 KB
testcase_62 AC 44 ms
49,436 KB
testcase_63 AC 43 ms
49,772 KB
testcase_64 AC 43 ms
49,448 KB
testcase_65 AC 43 ms
49,452 KB
testcase_66 AC 42 ms
49,428 KB
testcase_67 AC 43 ms
50,068 KB
testcase_68 AC 42 ms
49,476 KB
testcase_69 AC 43 ms
49,872 KB
testcase_70 AC 42 ms
49,500 KB
testcase_71 AC 42 ms
49,620 KB
testcase_72 AC 42 ms
49,412 KB
testcase_73 AC 42 ms
49,544 KB
testcase_74 AC 42 ms
49,488 KB
testcase_75 AC 41 ms
49,472 KB
testcase_76 AC 42 ms
49,408 KB
testcase_77 AC 43 ms
49,876 KB
testcase_78 AC 43 ms
49,356 KB
testcase_79 AC 42 ms
49,836 KB
testcase_80 AC 42 ms
49,824 KB
testcase_81 AC 43 ms
49,440 KB
testcase_82 AC 43 ms
49,580 KB
testcase_83 AC 42 ms
49,476 KB
testcase_84 AC 43 ms
49,320 KB
testcase_85 AC 43 ms
49,904 KB
testcase_86 AC 44 ms
49,552 KB
testcase_87 AC 44 ms
49,476 KB
testcase_88 AC 44 ms
49,464 KB
testcase_89 AC 43 ms
49,516 KB
testcase_90 AC 42 ms
49,836 KB
testcase_91 AC 42 ms
49,360 KB
testcase_92 AC 41 ms
49,424 KB
testcase_93 AC 42 ms
49,556 KB
testcase_94 AC 43 ms
49,828 KB
testcase_95 AC 43 ms
49,280 KB
testcase_96 AC 45 ms
49,316 KB
testcase_97 AC 42 ms
49,396 KB
testcase_98 AC 41 ms
49,360 KB
testcase_99 AC 42 ms
49,432 KB
testcase_100 AC 42 ms
49,428 KB
testcase_101 AC 42 ms
49,560 KB
testcase_102 AC 42 ms
49,528 KB
testcase_103 AC 43 ms
49,500 KB
testcase_104 AC 42 ms
49,420 KB
testcase_105 AC 43 ms
49,436 KB
testcase_106 AC 42 ms
49,484 KB
testcase_107 AC 42 ms
49,324 KB
testcase_108 AC 42 ms
47,808 KB
testcase_109 AC 42 ms
49,696 KB
testcase_110 AC 43 ms
49,472 KB
testcase_111 AC 43 ms
49,940 KB
testcase_112 AC 42 ms
49,476 KB
testcase_113 AC 42 ms
49,524 KB
testcase_114 AC 42 ms
49,464 KB
testcase_115 AC 42 ms
49,552 KB
testcase_116 AC 43 ms
49,456 KB
testcase_117 AC 41 ms
49,744 KB
testcase_118 AC 41 ms
49,544 KB
testcase_119 AC 42 ms
49,536 KB
testcase_120 AC 42 ms
49,836 KB
testcase_121 AC 42 ms
49,324 KB
testcase_122 AC 42 ms
49,356 KB
testcase_123 AC 41 ms
49,400 KB
testcase_124 AC 42 ms
49,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	static MLScanner sc = new MLScanner(System.in);
	static PrintWriter ot = new PrintWriter(System.out);
	static String sp = " ";
	public static void main(String[] args) {
		int T = 1;
		for(int i=0;i<T;i++) {
			long A = sc.nextLong();
			long B = sc.nextLong();
			long C = sc.nextLong();
			double a = A;
			double b = B;
			double c = C;
			if(A==0&&B==0) {
				if(C==0)ot.println(-1);
				else ot.println(0);
			}else if(A==0) {
				ot.println(1);
				ot.println(-c/b);
			}else {
				if(B<0) {
					A *= -1;
					B *= -1;
					C *= -1;
					a *= -1;
					b *= -1;
					c *= -1;
				}
				long D = B*B-4*A*C;
				if(D<0) ot.println(0);
				else if(D==0) {
					ot.println(1);
					ot.println(-b/(2*a));
				}
				else {
					double ans1 = -(b+Math.sqrt(D))/(2*a);
					double ans2 = -(B*B-D)/(2*a*(b+Math.sqrt(D)));
					if(ans1>ans2) {
						double tmp = ans1;
						ans1 = ans2;
						ans2 = tmp;
					}
					ot.println(2);
					ot.println(ans1);
					ot.println(ans2);
				}
			}
		}
		ot.flush();
	
	}
}

class MLScanner {
	  private static final int BUFFER_SIZE = 1024;
	  
	  private final InputStream stream;
	  private final byte[] buffer;
	  private int pointer;
	  private int bufferLength;
	  
	  MLScanner(InputStream stream) {
	    this.stream = stream;
	    this.buffer = new byte[BUFFER_SIZE];
	    this.pointer = 0;
	    this.bufferLength = 0;
	  }
	  
	  private boolean hasNextByte() {
	    if (pointer < bufferLength) {
	      return true;
	    }
	    
	    pointer = 0;
	    try {
	      bufferLength = stream.read(buffer);
	    } catch (IOException e) {
	      throw new RuntimeException(e);
	    }
	    return bufferLength > 0;
	  }
	  
	  private int readByte() {
	    if (hasNextByte()) {
	      return buffer[pointer++];
	    } else {
	      return -1;
	    }
	  }
	  
	  private static boolean isPrintableChar(int c) {
	    return 33 <= c && c <= 126;
	  }
	  
	  public boolean hasNext() {
	    while (hasNextByte() && !isPrintableChar(buffer[pointer])) {
	      pointer++;
	    }
	    return hasNextByte();
	  }
	  
	  public String next() {
	    if (!hasNext()) {
	      throw new NoSuchElementException();
	    }
	    StringBuilder sb = new StringBuilder();
	    while(true) {
	      int b = readByte();
	      if (!isPrintableChar(b)) {
	        break;
	      }
	      sb.appendCodePoint(b);
	    }
	    return sb.toString();
	  }
	  
	  public char nextChar() {
	    return next().charAt(0);
	  }
	  
	  public int nextInt() {
	    long nl = nextLong();
	    if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
	      throw new NumberFormatException();
	    }
	    return (int) nl;
	  }
	  
	  public long nextLong() {
	    if (!hasNext()) {
	      throw new NoSuchElementException();
	    }
	    
	    long n = 0;
	    boolean minus = false;
	    
	    {
	      int b = readByte();
	      if (b == '-') {
	        minus = true;
	      } else if ('0' <= b && b <= '9') {
	        n = b - '0';
	      } else {
	        throw new NumberFormatException();
	      }
	    }
	    
	    while(true){
	      int b = readByte();
	      if ('0' <= b && b <= '9') {
	        n *= 10;
	        n += b - '0';
	      } else if (b == -1 || !isPrintableChar(b)) {
	        return minus ? -n : n;
	      } else {
	        throw new NumberFormatException();
	      }
	    }
	  }
	  
	  public double nextDouble() {
	    return Double.parseDouble(next());
	  }
	  
	  public String[] next(int n) {
	    String[] array = new String[n];
	    for (int i = 0; i < n; i++) {
	      array[i] = next();
	    }
	    return array;
	  }
	  
	  public char[] nextChar(int n) {
	    char[] array = new char[n];
	    for (int i = 0; i < n; i++) {
	      array[i] = nextChar();
	    }
	    return array;
	  }
	  
	  public int[] nextInt(int n) {
	    int[] array = new int[n];
	    for (int i = 0; i < n; i++) {
	      array[i] = nextInt();
	    }
	    return array;
	  }
	  
	  public long[] nextLong(int n) {
	    long[] array = new long[n];
	    for (int i = 0; i < n; i++) {
	      array[i] = nextLong();
	    }
	    return array;
	  }
	  
	  public double[] nextDouble(int n) {
	    double[] array = new double[n];
	    for (int i = 0; i < n; i++) {
	      array[i] = nextDouble();
	    }
	    return array;
	  }
	  
	  public char[] nextCharArray() {
	    return next().toCharArray();
	  }
	  
	  public int[][] nextInt(int n, int m) {
	    int[][] matrix = new int[n][m];
	    for (int i = 0; i < n; i++) {
	      for (int j = 0; j < m; j++) {
	        matrix[i][j] = nextInt();
	      }
	    }
	    return matrix;
	  }
	  
	  public char[][] nextChar(int n, int m) {
	    char[][] matrix = new char[n][m];
	    for (int i = 0; i < n; i++) {
	      for (int j = 0; j < m; j++) {
	        matrix[i][j] = nextChar();
	      }
	    }
	    return matrix;
	  }
	  
	  public long[][] nextLong(int n, int m) {
	    long[][] matrix = new long[n][m];
	    for (int i = 0; i < n; i++) {
	      for (int j = 0; j < m; j++) {
	        matrix[i][j] = nextLong();
	      }
	    }
	    return matrix;
	  }
	  
	  public double[][] nextDouble(int n, int m) {
	    double[][] matrix = new double[n][m];
	    for (int i = 0; i < n; i++) {
	      for (int j = 0; j < m; j++) {
	        matrix[i][j] = nextDouble();
	      }
	    }
	    return matrix;
	  }
	  
	  public char[][] nextCharArray(int n) {
	    char[][] matrix = new char[n][];
	    for (int i = 0; i < n; i++) {
	      matrix[i] = next().toCharArray();
	    }
	    return matrix;
	  }
	}

0