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 Solution { | |
def main(args: Array[String]) { | |
val lines = io.Source.stdin.getLines().drop(1).toList | |
val tcs = lines.map(l => l.toInt).grouped(3) | |
def resolve(steps: Int, a: Int, b: Int) : List[String] = { | |
val maxs = (0 to steps ).map(n => n * a + (steps -n) * b) | |
maxs.distinct.sorted.toList.map(n => n.toString) | |
} | |
tcs.foreach(c => println( resolve(c(0) -1,c(1),c(2)).mkString(" ") )) | |
} |
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 Solution { | |
def main(args: Array[String]) { | |
val lines = io.Source.stdin.getLines().toList | |
val jars = lines(0).split("\\s+")(0).toInt | |
val ops = lines.drop(1).map( l => l.split("\\s+").map(s => s.toLong)) | |
val rslt = ops.foldLeft(0L)( (acc, v) => acc + ( (v(1) - v(0) + 1) * v(2) )) | |
println(rslt / jars) | |
} | |
} |
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 Solution { | |
def main(args: Array[String]) { | |
val lines = io.Source.stdin.getLines().drop(1).toList | |
lines.foreach( l =>{ | |
val num = l.toInt | |
println(l.map(c => c.asDigit).count( d => d != 0 && num % d == 0)) | |
} ) | |
} | |
} |
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 Solution { | |
def maxXor(l: Int, r: Int): Int = { | |
var maxV :Int = 0; | |
for(i <- l to r; j <- i to r) | |
maxV = maxV.max( i ^ j) | |
maxV | |
} | |
def main(args: Array[String]) { |
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 Solution { | |
def main(args: Array[String]) { | |
val line = io.Source.stdin.getLines().filter(_.length > 0).take(1).toList(0) | |
def existsPalindrome(str:String):Boolean = { | |
val freqs = str.groupBy( k => k) | |
freqs.count( { case (k,v ) => v.length %2 == 1 } ) <= 1 | |
} | |
println (if(existsPalindrome(line)) "YES" else "NO") |
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 Solution { | |
def main(args: Array[String]) { | |
val lines = io.Source.stdin.getLines().filter(_.length > 0).drop(1) | |
val nums = lines.map(_.toLong) | |
nums.foreach( n => println( (n /2) * ( n - n /2) )) | |
} | |
} |
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 Solution { | |
def main(args: Array[String]) { | |
val lines = io.Source.stdin.getLines().toList | |
val segs = lines(1).split("\\s+").map(_.toInt) | |
val testcases = lines.drop(2) | |
for( tc <- testcases){ | |
val p = tc.split("\\s+").map(_.toInt).toList | |
println(segs.slice(p(0), p(1) + 1).min) | |
} | |
} |
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 Solution { | |
def main(args: Array[String]) { | |
val lines = io.Source.stdin.getLines().filter(_.length > 0).drop(1) | |
val nums = lines.map(_.toInt) | |
nums.foreach( n => println( (0 to n).fold(0)( (acc, n) => if(n %2 == 0) acc +1 else acc *2 )) ) | |
} | |
} |
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.immutable.StringOps; | |
object Solution { | |
def main(args: Array[String]) { | |
val lines = io.Source.stdin.getLines().toList | |
for(line <- lines.drop(1)) | |
{ | |
val l = line; | |
var (first, tmpSecond) = l.splitAt(l.size /2 ) | |
val second = if(first.length() != tmpSecond.length()) tmpSecond.drop(1).reverse |
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 Solution { | |
def intersect(a: Set[Char], b: Set[Char]) = a & b | |
def main(args: Array[String]) { | |
val lines =io.Source.stdin.getLines().toList | |
val cases = lines.drop(1) | |
val caseSets = cases.map(c => c.distinct).map(c => c.toSet) | |
val resultSet = caseSets.reduce(intersect) | |
println(resultSet.size) | |
} | |
} |
NewerOlder