結果

問題 No.955 ax^2+bx+c=0
ユーザー yakamotoyakamoto
提出日時 2019-12-23 23:00:28
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 995 ms / 2,000 ms
コード長 4,786 bytes
コンパイル時間 12,838 ms
コンパイル使用メモリ 267,228 KB
実行使用メモリ 65,608 KB
最終ジャッジ日時 2024-05-16 06:23:37
合計ジャッジ時間 117,329 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 834 ms
65,472 KB
testcase_01 AC 813 ms
65,608 KB
testcase_02 AC 752 ms
63,996 KB
testcase_03 AC 738 ms
63,656 KB
testcase_04 AC 760 ms
63,692 KB
testcase_05 AC 746 ms
63,764 KB
testcase_06 AC 745 ms
63,824 KB
testcase_07 AC 740 ms
63,648 KB
testcase_08 AC 743 ms
63,728 KB
testcase_09 AC 744 ms
63,644 KB
testcase_10 AC 740 ms
63,848 KB
testcase_11 AC 742 ms
63,820 KB
testcase_12 AC 756 ms
63,660 KB
testcase_13 AC 753 ms
63,620 KB
testcase_14 AC 833 ms
65,392 KB
testcase_15 AC 837 ms
65,560 KB
testcase_16 AC 822 ms
65,540 KB
testcase_17 AC 830 ms
65,332 KB
testcase_18 AC 995 ms
65,400 KB
testcase_19 AC 840 ms
65,420 KB
testcase_20 AC 846 ms
65,320 KB
testcase_21 AC 840 ms
65,388 KB
testcase_22 AC 814 ms
65,416 KB
testcase_23 AC 826 ms
65,404 KB
testcase_24 AC 835 ms
65,464 KB
testcase_25 AC 831 ms
65,608 KB
testcase_26 AC 826 ms
65,580 KB
testcase_27 AC 826 ms
65,560 KB
testcase_28 AC 823 ms
65,580 KB
testcase_29 AC 836 ms
65,432 KB
testcase_30 AC 831 ms
65,332 KB
testcase_31 AC 837 ms
65,412 KB
testcase_32 AC 846 ms
65,476 KB
testcase_33 AC 834 ms
65,468 KB
testcase_34 AC 843 ms
65,520 KB
testcase_35 AC 828 ms
65,372 KB
testcase_36 AC 833 ms
65,520 KB
testcase_37 AC 841 ms
65,460 KB
testcase_38 AC 850 ms
65,444 KB
testcase_39 AC 831 ms
65,520 KB
testcase_40 AC 845 ms
65,496 KB
testcase_41 AC 846 ms
65,344 KB
testcase_42 AC 848 ms
65,444 KB
testcase_43 AC 837 ms
65,284 KB
testcase_44 AC 840 ms
65,456 KB
testcase_45 AC 823 ms
65,476 KB
testcase_46 AC 816 ms
65,584 KB
testcase_47 AC 826 ms
65,388 KB
testcase_48 AC 823 ms
65,528 KB
testcase_49 AC 825 ms
65,372 KB
testcase_50 AC 835 ms
65,424 KB
testcase_51 AC 825 ms
65,308 KB
testcase_52 AC 828 ms
65,432 KB
testcase_53 AC 814 ms
65,468 KB
testcase_54 AC 798 ms
65,532 KB
testcase_55 AC 813 ms
65,556 KB
testcase_56 AC 822 ms
65,604 KB
testcase_57 AC 820 ms
65,396 KB
testcase_58 AC 837 ms
65,288 KB
testcase_59 AC 824 ms
65,432 KB
testcase_60 AC 745 ms
63,972 KB
testcase_61 AC 771 ms
63,712 KB
testcase_62 AC 821 ms
65,536 KB
testcase_63 AC 806 ms
65,552 KB
testcase_64 AC 738 ms
63,884 KB
testcase_65 AC 821 ms
65,476 KB
testcase_66 AC 731 ms
63,760 KB
testcase_67 AC 820 ms
65,420 KB
testcase_68 AC 737 ms
63,692 KB
testcase_69 AC 827 ms
65,468 KB
testcase_70 AC 817 ms
65,264 KB
testcase_71 AC 730 ms
63,848 KB
testcase_72 AC 745 ms
63,748 KB
testcase_73 AC 820 ms
65,564 KB
testcase_74 AC 829 ms
65,464 KB
testcase_75 AC 752 ms
63,668 KB
testcase_76 AC 739 ms
63,740 KB
testcase_77 AC 829 ms
65,340 KB
testcase_78 AC 845 ms
65,460 KB
testcase_79 AC 831 ms
65,504 KB
testcase_80 AC 750 ms
63,696 KB
testcase_81 AC 819 ms
65,552 KB
testcase_82 AC 824 ms
65,404 KB
testcase_83 AC 824 ms
65,448 KB
testcase_84 AC 856 ms
65,516 KB
testcase_85 AC 844 ms
65,324 KB
testcase_86 AC 828 ms
65,424 KB
testcase_87 AC 815 ms
65,404 KB
testcase_88 AC 816 ms
65,300 KB
testcase_89 AC 824 ms
65,380 KB
testcase_90 AC 818 ms
65,276 KB
testcase_91 AC 815 ms
65,288 KB
testcase_92 AC 737 ms
63,924 KB
testcase_93 AC 755 ms
63,728 KB
testcase_94 AC 825 ms
65,436 KB
testcase_95 AC 825 ms
65,164 KB
testcase_96 AC 821 ms
65,380 KB
testcase_97 AC 824 ms
65,548 KB
testcase_98 AC 825 ms
65,416 KB
testcase_99 AC 822 ms
65,256 KB
testcase_100 AC 737 ms
63,792 KB
testcase_101 AC 823 ms
65,412 KB
testcase_102 AC 823 ms
65,296 KB
testcase_103 AC 821 ms
65,400 KB
testcase_104 AC 826 ms
65,252 KB
testcase_105 AC 839 ms
65,380 KB
testcase_106 AC 886 ms
65,408 KB
testcase_107 AC 816 ms
65,300 KB
testcase_108 AC 826 ms
65,352 KB
testcase_109 AC 824 ms
65,444 KB
testcase_110 AC 823 ms
65,548 KB
testcase_111 AC 829 ms
65,228 KB
testcase_112 AC 829 ms
65,260 KB
testcase_113 AC 837 ms
65,304 KB
testcase_114 AC 837 ms
65,376 KB
testcase_115 AC 841 ms
65,324 KB
testcase_116 AC 826 ms
65,356 KB
testcase_117 AC 826 ms
65,528 KB
testcase_118 AC 817 ms
65,544 KB
testcase_119 AC 806 ms
65,308 KB
testcase_120 AC 817 ms
65,292 KB
testcase_121 AC 816 ms
65,376 KB
testcase_122 AC 821 ms
65,488 KB
testcase_123 AC 822 ms
65,252 KB
testcase_124 AC 813 ms
65,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private[this] val oj = System.getenv("MY_DEBUG") == null
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Int]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  def debug(s: => String): Unit = {
    if (!oj){ System.err.println(s) }
  }
  def isDebug[A](debug: => A, online: => A): A = {
    if (oj) online else debug
  }

  class InputReader(val stream: InputStream) {
    private[this] val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private[this] var tokenizer: StringTokenizer = _

    private[this] def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = next()
    def ns(n: Int): Array[Char] = ns().toCharArray
    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }
    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }
    def nal(n: Int): Array[Long] = map(n)(_ => nl())
    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }
  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }
  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }
  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Workspace {
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer
  import Workspace._
  import Integer.signum
  import Math.sqrt

  // toIntとか+7とかするならvalにしろ
  final private[this] val MOD = 1000000007

  def solve(): Unit = {
    solve2() match {
      case None => out.println(-1)
      case Some(ans) =>
        out.println(ans.length)
        ans.foreach(a => out.println(f"$a%.15f"))
    }
  }

  def solve2(): Option[Seq[BigDecimal]] = {
    val a, b, c = ni()

    val inf = None
    val none = Some(Seq.empty[BigDecimal])

    if (a == 0) {
      if (b == 0) {
        if (c == 0) inf // 無限
        else none // 解なし
      } else {
        Some(Seq(BigDecimal(-c) / b))
      }
    } else {
      val v = b.toLong*b - 4.toLong*a*c
      if (v < 0) {
        none // 虚数
      } else if (v == 0) {
        Some(Seq(-b.toDouble/(2*a)))
      } else {
        val n = sqrt(v)
        debug(f"n:$n%.15f")
        val x1 = if (b > 0) {
          (-b.toDouble - n) / (2 * a)
        } else {
          (-b.toDouble + n) / (2 * a)
        }
        val x2 = c.toDouble / a / x1
        Some(Seq(min(x1, x2), max(x1, x2)))
      }
    }
  }
}
0