結果

問題 No.955 ax^2+bx+c=0
ユーザー Goryudyuma
提出日時 2020-01-04 19:41:15
言語 Scala(Beta)
(2.13.1)
結果
WA   .
実行時間 -
コード長 8,047 Byte
コンパイル時間 15,713 ms
使用メモリ 52,928 KB
最終ジャッジ日時 2020-01-04 19:43:32

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
0_sample1.txt WA -
0_sample2.txt AC 912 ms
52,764 KB
0_sample3.txt AC 544 ms
50,840 KB
1_test1.txt AC 540 ms
50,968 KB
1_test2.txt AC 684 ms
50,736 KB
1_test3.txt AC 656 ms
50,944 KB
1_test4.txt AC 528 ms
50,800 KB
1_test5.txt AC 532 ms
50,812 KB
1_test6.txt AC 536 ms
50,672 KB
1_test7.txt AC 768 ms
51,036 KB
1_test8.txt AC 552 ms
50,932 KB
1_test9.txt AC 528 ms
50,720 KB
1_test10.txt AC 624 ms
50,820 KB
1_test11.txt AC 692 ms
50,952 KB
1_test12.txt AC 632 ms
52,728 KB
1_test13.txt AC 732 ms
52,628 KB
1_test14.txt AC 760 ms
52,724 KB
1_test15.txt AC 644 ms
52,728 KB
1_test16.txt AC 632 ms
52,636 KB
1_test17.txt AC 760 ms
52,616 KB
1_test18.txt AC 764 ms
52,804 KB
1_test19.txt AC 636 ms
52,776 KB
1_test20.txt AC 616 ms
52,796 KB
1_test21.txt AC 748 ms
52,732 KB
1_test22.txt AC 1,064 ms
52,660 KB
1_test23.txt AC 640 ms
52,832 KB
1_test24.txt AC 632 ms
52,736 KB
1_test25.txt AC 748 ms
52,736 KB
1_test26.txt AC 748 ms
52,672 KB
1_test27.txt AC 632 ms
52,716 KB
1_test28.txt AC 636 ms
52,700 KB
1_test29.txt AC 776 ms
52,600 KB
1_test30.txt AC 732 ms
52,728 KB
1_test31.txt AC 636 ms
52,676 KB
2_test1.txt WA -
2_test2.txt WA -
2_test3.txt WA -
2_test4.txt WA -
2_test5.txt WA -
2_test6.txt WA -
2_test7.txt WA -
2_test8.txt WA -
2_test9.txt WA -
2_test10.txt WA -
2_test11.txt WA -
2_test12.txt WA -
2_test13.txt WA -
2_test14.txt WA -
2_test15.txt WA -
2_test16.txt WA -
2_test17.txt WA -
2_test18.txt WA -
2_test19.txt WA -
2_test20.txt WA -
2_test21.txt WA -
2_test22.txt WA -
2_test23.txt WA -
2_test24.txt WA -
3_test1.txt WA -
3_test2.txt WA -
3_test3.txt WA -
3_test4.txt WA -
5_gen_case1.txt AC 808 ms
52,724 KB
5_gen_case2.txt WA -
5_gen_case3.txt AC 692 ms
50,764 KB
5_gen_case4.txt WA -
5_gen_case5.txt AC 860 ms
50,876 KB
5_gen_case6.txt AC 956 ms
52,744 KB
5_gen_case7.txt AC 720 ms
50,688 KB
5_gen_case8.txt AC 928 ms
52,648 KB
5_gen_case9.txt WA -
5_gen_case10.txt AC 696 ms
50,952 KB
5_gen_case11.txt AC 1,056 ms
50,896 KB
5_gen_case12.txt AC 1,128 ms
52,640 KB
5_gen_case13.txt AC 1,116 ms
52,764 KB
5_gen_case14.txt AC 876 ms
50,748 KB
5_gen_case15.txt AC 1,016 ms
50,608 KB
5_gen_case16.txt WA -
5_gen_case17.txt WA -
5_gen_case18.txt WA -
5_gen_case19.txt AC 1,092 ms
50,616 KB
5_gen_case20.txt AC 1,188 ms
52,776 KB
6_gen_case1.txt AC 1,060 ms
52,588 KB
6_gen_case2.txt AC 1,680 ms
52,812 KB
6_gen_case3.txt AC 1,036 ms
52,764 KB
6_gen_case4.txt AC 1,264 ms
52,812 KB
6_gen_case5.txt AC 984 ms
52,812 KB
6_gen_case6.txt AC 1,008 ms
52,616 KB
6_gen_case7.txt AC 704 ms
52,724 KB
6_gen_case8.txt AC 1,004 ms
52,752 KB
6_gen_case9.txt AC 948 ms
52,796 KB
6_gen_case10.txt AC 1,000 ms
52,852 KB
7_gen_case1.txt AC 888 ms
50,928 KB
7_gen_case2.txt AC 1,332 ms
50,796 KB
7_gen_case3.txt AC 972 ms
52,804 KB
7_gen_case4.txt AC 956 ms
52,720 KB
7_gen_case5.txt AC 964 ms
52,664 KB
7_gen_case6.txt AC 816 ms
52,744 KB
7_gen_case7.txt AC 812 ms
52,664 KB
7_gen_case8.txt AC 972 ms
52,740 KB
7_gen_case9.txt AC 700 ms
50,728 KB
7_gen_case10.txt AC 972 ms
52,812 KB
8_gen_case1.txt AC 968 ms
52,772 KB
8_gen_case2.txt AC 800 ms
52,468 KB
8_gen_case3.txt AC 980 ms
52,768 KB
8_gen_case4.txt AC 972 ms
52,652 KB
8_gen_case5.txt AC 804 ms
52,864 KB
8_gen_case6.txt AC 968 ms
52,664 KB
8_gen_case7.txt AC 796 ms
52,728 KB
8_gen_case8.txt AC 808 ms
52,524 KB
8_gen_case9.txt AC 996 ms
52,760 KB
8_gen_case10.txt AC 980 ms
52,752 KB
8_gen_case11.txt AC 984 ms
52,728 KB
8_gen_case12.txt AC 976 ms
52,748 KB
8_gen_case13.txt AC 1,144 ms
52,696 KB
8_gen_case14.txt AC 992 ms
52,772 KB
8_gen_case15.txt AC 1,004 ms
52,728 KB
8_gen_case16.txt AC 1,008 ms
52,928 KB
8_gen_case17.txt AC 980 ms
52,472 KB
8_gen_case18.txt AC 1,088 ms
52,828 KB
8_gen_case19.txt AC 1,048 ms
52,768 KB
8_gen_case20.txt AC 1,004 ms
52,856 KB
90_match_case1.txt WA -
90_match_case2.txt WA -
99_system_test1.txt WA -
テストケース一括ダウンロード

ソースコード

diff #
//import java.util.Scanner

import java.io._
import java.nio.file.Files._
import java.nio.file.Path
import java.util.StringTokenizer

import scala.collection.immutable._
import scala.io.Codec

/**
  * Scala implementation of a faster java.util.Scanner
  * See: http://codeforces.com/blog/entry/7018
  */

class Scanner(reader: LineNumberReader) extends Iterable[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))

  def this(reader: Reader) = this(new BufferedReader(reader))

  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))

  def this(path: Path)(implicit codec: Codec) = this(newBufferedReader(path, codec.charSet))

  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)

  def this(str: String) = this(new StringReader(str))

  override def iterator: Iterator[String] = for {
    line <- Iterator.continually(reader.readLine()).takeWhile(_ != null)
    tokenizer = new StringTokenizer(line)
    tokens <- Iterator.continually(tokenizer).takeWhile(_.hasMoreTokens)
  } yield tokens.nextToken()

  private[this] var current = iterator

  def hasNext: Boolean = current.hasNext

  @inline def next(): String = current.next()

  /**
    * This is different from Java's scanner.nextLine
    * The Java one is a misnomer since it actually travel to end of current line
    * This one actually does fetch the next line
    */
  def nextLine(): String = {
    val line = reader.readLine()
    current = iterator
    line
  }

  def lineNumber: Int = reader.getLineNumber

  def nextString(): String = next()

  def nextBoolean(): Boolean = next().toBoolean

  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)

  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)

  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)

  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)

  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)

  def nextFloat(): Float = next().toFloat

  def nextDouble(): Double = next().toDouble

  def nextBigDecimal(): BigDecimal = BigDecimal(next())

  override def close(): Unit = reader.close()
}


class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(Node(None, treeSize = 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) =>
      nodes(t).parent = Some(root(p))
      nodes(t).parent.get
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val A, B, C = sc.nextDouble()
    if (A == 0) {
      if (B == 0) {
        if (C == 0) println(-1)
        else println(0)
      } else {
        println(1)
        println("%.11f".format(-(C / B)))
      }
    } else {
      if (B * B - 4 * A * C < 0) println(0)
      else {
        if (Math.abs(B * B - 4 * A * C) < 1e-6) {
          println(1)
          println("%.11f".format(-B / (2 * A)))
        }
        else {
          println(2)
          println("%.11f".format((-B - sqt(B.toLong * B.toLong - 4 * A.toLong * C.toLong)) / (2 * A)))
          println("%.11f".format((-B + sqt(B.toLong * B.toLong - 4 * A.toLong * C.toLong)) / (2 * A)))
        }
      }
    }
  }

  def sqt(n: Long): Double = {
    val d = n
    var a: Double = 1.0
    var b: Double = d
    while (b - a >= 0) {
      val mid = (a + b) / 2
      if (mid * mid - d > 0) b = mid - 0.0000003 //adjust down
      else a = mid + 0.0000003 //adjust up
    }
    b
  }

  def recursive(N: Long): Long = {
    if (N == 0) 1 else recursive(N - 1) * 5 + 1
  }

  implicit class implicitInt(val N: Int) {
    def times[B](function: Int => B): IndexedSeq[B] = (0 until N).map(function)
  }

  def calc(N: Long): Long = {
    if (N == 0) 0 else if (N % 9 == 0) 9 else N % 9
  }

  def time(s: String): Int =
    s.substring(0, 2).toInt * 60 + s.substring(3, 5).toInt

  def getPermutation(begin: Long = 0): Stream[Long] =
    Stream.cons(begin, getPermutation(begin + 1))

  def getFibonacci(prevprev: Long = 0, prev: Long = 1): Stream[Long] =
    Stream.cons(prevprev, getFibonacci(prev, prevprev + prev))

  var memo: Map[(Long, Long), Long] = Map[(Long, Long), Long]()

  @scala.annotation.tailrec
  def recursive2(X: Set[Long], Y: Stream[Long]): Long = if (X.contains(Y.head)) X.size else recursive2(X + Y.head, Y.tail)

  def check(i: Int, X: String): Long = {
    if (X == "") 0 else check(i, X.tail) * i + X.head.toString.toLong
  }

  def shift(n: Long): Long = {
    if (n == 0) 0
    else if (n == 1) 1
    else shift(n - 1) << 1
  }

  def unShift(n: Long): Long = {
    if (n == 0) 0
    else unShift(n >> 1) + 1
  }

  @scala.annotation.tailrec
  def gcd(i: Long, j: Long): Long = {
    if (i < j) gcd(j, i)
    else if (j == 0) i
    else gcd(j, i % j)
  }

  def primeFactors(i: Long): List[Long] = primeFactors_(i, 1).sorted


  def primeFactors_(i: Long, j: Long): List[Long] = {
    if (j * j > i) List.empty else if (i % j == 0) primeFactors_(i, j + 1) ++ List[Long](j, i / j) else primeFactors_(i, j + 1)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

object Util {
  def getPermutation(begin: Long = 0): Stream[Long] =
    Stream.cons(begin, getPermutation(begin + 1))

  def getPrimeList: Stream[Long] =
    getPrimeListRecursive(getPermutation(begin = 2))

  private def getPrimeListRecursive(A: Stream[Long]): Stream[Long] =
    Stream.cons(A.head, getPrimeListRecursive(A.tail.filter(_ % A.head != 0)))

  def fib(a: Long = 0, b: Long = 1, mod: Long = Long.MaxValue): Stream[Long] = a #:: fib(b % mod, (a + b) % mod, mod)
}

object ArabicRoman {

  type =?>[A, B] = PartialFunction[A, B]

  private val codeTable: List[(Int, String)] = List(
    (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"),
    (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I"))

  val arabicToRoman: Int =?> String = {
    case src if src >= 1 && src <= 3999 =>

      @scala.annotation.tailrec
      def convert(left: Int, cont: String = "", code: List[(Int, String)] = codeTable): String = {
        val (unitVal, unitChar) = code.head
        left - unitVal match {
          case n if n == 0 => cont + unitChar
          case n if n > 0 => convert(n, cont + unitChar, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src)
  }

  val romanToArabic: String =?> Int = {
    case src if Option(src).exists { s => {
      s.nonEmpty && """[^MDCLXVI]""".r.findFirstMatchIn(s.toUpperCase).isEmpty
    }
    } =>

      @scala.annotation.tailrec
      def convert(left: String, cont: Int = 0, code: List[(Int, String)] = codeTable): Int = {
        val (unitVal, unitChar) = code.head
        left.splitAt(unitChar.length) match {
          case ("", _) => cont
          case (`unitChar`, tail) => convert(tail, cont + unitVal, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src.toUpperCase())
  }
}

object PowMod {
  def naivePowMod(a: Long, k: Long, m: Long): Long = {
    var t: Long = 1
    val aMod: Long = a % m

    for (_ <- 1L to k) {
      t = ((t % m) * aMod) % m
    }
    t.toInt
  }

  def powMod(a: Long, k: Long, m: Long): Long = {
    if (k == 0) 1
    else {
      val t = powMod(a, k / 2, m)
      if ((k % 2) == 0) (t * t) % m else (((t * t) % m) * a) % m
    }
  }
}
0