This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Main | |
import java.io.{FileOutputStream, FileInputStream} | |
import scala.annotation.tailrec | |
import scala.io.StdIn | |
case class Num(num:Long, count:Long) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.io.Source | |
import scala.annotation.tailrec | |
object Main { | |
def findGreaterThan(kens: List[Double], value: Double): Double = { | |
kens.filter(_ > value).last | |
} | |
def war(naomies: List[Double], kens: List[Double]): Int = { | |
if (naomies.isEmpty) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.PrintWriter | |
import scala.io.Source | |
import java.io.File | |
object Main { | |
def gcd(p: BigInt, q: BigInt): BigInt = if (q == 0) p else gcd(q, p % q) | |
def solve(p: BigInt, q: BigInt, r: Int = 0): String = q.bitCount == 1 match { | |
case true => p >= q match { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.{FileOutputStream, File, PrintWriter} | |
import scala.collection.mutable.ListBuffer | |
import scala.io.Source | |
object Main { | |
def solve(input: List[(String, String)]): String = { | |
val mans = (input.map(_._1) ::: input.map(_._2)).toSet | |
// 사람 -> Set(싫어하는 사람 목록) | |
val mapping = (input ::: input.map{case (k, v) => (v, k)}).groupBy(_._1).map({case (k, v) => (k, v.map(_._2).toSet)}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable | |
object Main { | |
def search(index:Int, input:List[List[Int]], isVisited:mutable.Set[Int]):Boolean = { | |
if (isVisited.contains(index)) { | |
true | |
} else { | |
isVisited.add(index) | |
input(index).exists(nextIndex => search(nextIndex - 1, input, isVisited)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main { | |
def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b) | |
def solve(n: BigInt, pd: Int, pg: Int): Boolean = { | |
if ((0 == pg && 0 < pd) || 100 == pg && 100 > pd) { | |
false | |
} else { | |
n >= 100 / gcd(pd, 100) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable | |
object Main { | |
case class Item(count:Long, typeName:Long) | |
def solve(box:List[Item], toy:List[Item]): Long = { | |
var cache = mutable.HashMap[(List[Item], List[Item]), Long]() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main { | |
def solve(searchEngines:List[String], keywords:List[String]): Integer = { | |
val distance = searchEngines.map(x => (x, keywords.indexOf(x))) | |
.map(_._2).maxBy(x => if (-1 == x) Integer.MAX_VALUE else x) | |
if (-1 == distance) 0 | |
else solve(searchEngines, keywords.drop(distance)) + 1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val input = "2 20 8 2 3 5" | |
val normalSpeed = 0.5f | |
val boostSpeed = 1 | |
val split = input.split(" ").map(_ toInt) | |
val numBoosters = split(0) | |
val constructionTime = split(1) | |
val numStars = split(2) | |
val numDistances = split(3) | |
val distances = split.drop(4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main { | |
def toDirectories(path:String):Set[String] = { | |
path.split("/").drop(1). | |
foldLeft(List[String](""))( | |
(acc:List[String], x:String) => {(acc.head + "/" + x) :: acc} | |
).init.toSet | |
} |
OlderNewer