Submission #434055
Source Code Expand
import scala.io.StdIn.readLine
object Main{
def calc_score(board : Array[Array[Option[Boolean]]],
b : Array[Array[Int]],
c : Array[Array[Int]]) : (Int,Int) = {
var chokudai = 0
var chokuko = 0
for(i <- 0 to 1;
j <- 0 to 2){
val bij = b(i)(j)
if(board(i)(j).get == board(i+1)(j).get)
chokudai += bij
else
chokuko += bij
}
for(i <- 0 to 2;
j <- 0 to 1){
val cij = c(i)(j)
if(board(i)(j).get == board(i)(j+1).get)
chokudai += cij
else
chokuko += cij
}
(chokudai,chokuko)
}
def is_end(board : Array[Array[Option[Boolean]]]) = board.forall(_.forall(_.isDefined))
def turn(board : Array[Array[Option[Boolean]]],
b : Array[Array[Int]],
c : Array[Array[Int]],
chokudai : Boolean) : (Int,Int) = {
if(is_end(board)) calc_score(board,b,c)
else {
// val cand = (0 until 3).flatMap((i) =>
// (0 until 3).map((j) => {
// board(i)(j) match {
// case Some(_) => None
// case None => {
// board(i)(j) = Option(chokudai)
// val k = turn(board,b,c,!chokudai)
// board(i)(j) = None
// Option(k)
// }
// }
// }).collect({case Some(i) => i}))
val cand = (for(i <- 0 until 3;
j <- 0 until 3)
yield(i,j))
.filter({case (i,j) => board(i)(j).isEmpty})
.map({case (i,j) => {
board(i)(j) = Option(chokudai)
val k = turn(board,b,c,!chokudai)
board(i)(j) = None
k
}})
// var cand = List[(Int,Int)]()
// for(i <- 0 until 3;
// j <- 0 until 3){
// board(i)(j) match {
// case Some(_) => None
// case None => {
// board(i)(j) = Option(chokudai)
// cand = turn(board,b,c,!chokudai) :: cand
// board(i)(j) = None
// }
// }
// }
if(chokudai)
cand.maxBy(_._1)
else
cand.maxBy(_._2)
}
}
def main(args : Array[String]) : Unit = {
val board = Array.fill(3)(Array.fill(3)(Option.empty[Boolean]))
val b = (1 to 2).map((i) => readLine().split(" ").map(_.toInt)).toArray
val c = (1 to 3).map((i) => readLine().split(" ").map(_.toInt)).toArray
val last = turn(board,b,c,true)
println(last._1)
println(last._2)
}
}
Submission Info
Submission Time |
|
Task |
C - 双子と○×ゲーム |
User |
tomoki |
Language |
Scala (2.11.5) |
Score |
0 |
Code Size |
2909 Byte |
Status |
TLE |
Exec Time |
2035 ms |
Memory |
71656 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample-01.txt, sample-02.txt |
All |
test-01.txt, test-02.txt, test-03.txt, test-04.txt, test-05.txt, test-06.txt, test-07.txt, test-08.txt, test-09.txt, test-10.txt, test-11.txt, test-12.txt, test-13.txt, test-14.txt, test-15.txt, test-16.txt, test-17.txt, test-18.txt, test-19.txt, test-20.txt, sample-01.txt, sample-02.txt |
Case Name |
Status |
Exec Time |
Memory |
sample-01.txt |
TLE |
2033 ms |
71320 KB |
sample-02.txt |
TLE |
2033 ms |
71480 KB |
test-01.txt |
TLE |
2033 ms |
71196 KB |
test-02.txt |
TLE |
2034 ms |
71472 KB |
test-03.txt |
TLE |
2034 ms |
71108 KB |
test-04.txt |
TLE |
2032 ms |
70940 KB |
test-05.txt |
TLE |
2034 ms |
71260 KB |
test-06.txt |
TLE |
2032 ms |
71288 KB |
test-07.txt |
TLE |
2033 ms |
71428 KB |
test-08.txt |
TLE |
2033 ms |
71448 KB |
test-09.txt |
TLE |
2035 ms |
71616 KB |
test-10.txt |
TLE |
2035 ms |
71336 KB |
test-11.txt |
TLE |
2034 ms |
71544 KB |
test-12.txt |
TLE |
2033 ms |
71656 KB |
test-13.txt |
TLE |
2033 ms |
71432 KB |
test-14.txt |
TLE |
2035 ms |
71356 KB |
test-15.txt |
TLE |
2035 ms |
71588 KB |
test-16.txt |
TLE |
2035 ms |
71356 KB |
test-17.txt |
TLE |
2034 ms |
71504 KB |
test-18.txt |
TLE |
2034 ms |
71420 KB |
test-19.txt |
TLE |
2033 ms |
71248 KB |
test-20.txt |
TLE |
2034 ms |
71412 KB |