Skip to content

Commit 7e73c54

Browse files
committed
started doing scala problems
1 parent 8afafca commit 7e73c54

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

Diff for: codeforces/158/B.scala

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import scala.io.StdIn
2+
import scala.language.implicitConversions
3+
4+
object B {
5+
implicit def toInt(b: Boolean) = if (b) 1 else 0
6+
7+
def main(args: Array[String]) = {
8+
val n = StdIn.readLine.toInt
9+
val s = StdIn.readLine.split(" ").map(_.toInt)
10+
val freqMap: Map[Int, Int] = s.groupBy(x => x).mapValues(_.length)
11+
12+
val ones = freqMap.getOrElse(1, 0)
13+
val twos = freqMap.getOrElse(2, 0)
14+
val threes = freqMap.getOrElse(3, 0)
15+
val fours = freqMap.getOrElse(4, 0)
16+
17+
val mod = if (twos % 2 == 1) 2 else 0
18+
val ans = fours + threes + (twos + 1) / 2 + Math.max(ones - threes - mod + 3, 0) / 4
19+
println(ans)
20+
}
21+
}

Diff for: codeforces/158/b.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
n = int(raw_input())
2+
s = map(int, raw_input().split())
3+
freq_map = [0]*4
4+
for v in s:
5+
freq_map[v - 1] += 1
6+
7+
ans = freq_map[3]
8+
ans += freq_map[2]
9+
freq_map[0] -= freq_map[2]
10+
ans += (freq_map[1] + 1) / 2
11+
freq_map[0] -= 2 if freq_map[1] % 2 == 1 else 0
12+
freq_map[0] = max(freq_map[0], 0)
13+
ans += (freq_map[0] + 3) / 4
14+
15+
print ans

Diff for: codeforces/50/A.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.io.StdIn
2+
3+
object A {
4+
def main(args: Array[String]) = {
5+
val n :: m :: _ = StdIn.readf("{0,number} {1,number}").collect { case l: Long => l}
6+
println(n * m / 2)
7+
}
8+
}

0 commit comments

Comments
 (0)