def isFriend(pair: (Int, Int), check: Array[Int]): Boolean = {
def listToTuple(list: List[Int]): List[(Int, Int)] = list match {
case x :: xs => (x, xs.head) :: listToTuple(xs.tail)
case Nil => Nil
}
val checkList = listToTuple(check.toList)
checkList.exists { case (x, y) => ((x == pair._1 && y == pair._2) || (x == pair._2 && y == pair._1)) }
}
def factorial(n: Int): Int =
if (n == 0) 1
else n * factorial(n - 1)
override def main(args: Array[String]): Unit = {
val testCase = readInt()
val saveList: List[(String, String)] = for (count <- (0 until testCase).toList) yield (readLine(), readLine())
val values: List[Int] = saveList.map {
case (students, pair) =>
val numOfStudent: Array[Int] = students.split(" ").map(_.toInt)
val factori = factorial(numOfStudent(0) / 2)
val checkPair: Array[Int] = pair.split(" ").map(_.toInt)
makeTeam((0 until numOfStudent(0)).toList, List(Nil), checkPair).length / factori
}
values.map(println)
}
}
코드는 대략 이렇고..
입력 받는 부분인
val testCase = readInt()
val saveList: List[(String, String)] = for (count <- (0 until testCase).toList) yield (readLine(), readLine())
val values: List[Int] = saveList.map {
이부분에서 잘못된거 같은데 어디가 잘못됐는지 잘 모르겠습니다.
로컬에서는 잘 되고 잇거든요ㅜㅜ
fodrh
object Main extends App {
def makeTeam(numList: List[Int], acc: List[List[(Int, Int)]], check: Array[Int]): List[List[(Int, Int)]] = {
if (numList.isEmpty) acc
else
(for {
num1 <- numList
num2 <- numList if (num1 < num2) && isFriend((num1, num2), check)
} yield makeTeam(numList filter (elem => elem != num1 && elem != num2), acc.map((num1, num2) :: _), check)).flatten
}
def isFriend(pair: (Int, Int), check: Array[Int]): Boolean = {
def listToTuple(list: List[Int]): List[(Int, Int)] = list match {
case x :: xs => (x, xs.head) :: listToTuple(xs.tail)
case Nil => Nil
}
val checkList = listToTuple(check.toList)
checkList.exists { case (x, y) => ((x == pair._1 && y == pair._2) || (x == pair._2 && y == pair._1)) }
}
def factorial(n: Int): Int =
if (n == 0) 1
else n * factorial(n - 1)
override def main(args: Array[String]): Unit = {
val testCase = readInt()
val saveList: List[(String, String)] = for (count <- (0 until testCase).toList) yield (readLine(), readLine())
val values: List[Int] = saveList.map {
case (students, pair) =>
val numOfStudent: Array[Int] = students.split(" ").map(_.toInt)
val factori = factorial(numOfStudent(0) / 2)
val checkPair: Array[Int] = pair.split(" ").map(_.toInt)
makeTeam((0 until numOfStudent(0)).toList, List(Nil), checkPair).length / factori
}
values.map(println)
}
}
코드는 대략 이렇고..
입력 받는 부분인
val testCase = readInt()
val saveList: List[(String, String)] = for (count <- (0 until testCase).toList) yield (readLine(), readLine())
val values: List[Int] = saveList.map {
10년 전