結果

問題 No.24 数当てゲーム
ユーザー HujiLeeHujiLee
提出日時 2016-12-24 23:18:35
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 999 ms / 5,000 ms
コード長 1,428 bytes
コンパイル時間 14,243 ms
コンパイル使用メモリ 248,996 KB
実行使用メモリ 63,112 KB
最終ジャッジ日時 2023-09-12 09:14:46
合計ジャッジ時間 25,427 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 978 ms
62,784 KB
testcase_01 AC 992 ms
62,876 KB
testcase_02 AC 999 ms
62,776 KB
testcase_03 AC 992 ms
62,848 KB
testcase_04 AC 979 ms
62,992 KB
testcase_05 AC 992 ms
62,908 KB
testcase_06 AC 985 ms
62,860 KB
testcase_07 AC 983 ms
63,080 KB
testcase_08 AC 979 ms
62,848 KB
testcase_09 AC 974 ms
63,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.collection.mutable
import scala.io.StdIn

/**
  * Created by Administrator on 2016/12/24 0024.
  */
object Sub {
  def intersection(arrSet: mutable.HashSet[Array[Int]]): mutable.HashSet[Int] = {
    var count = 0
    var set = new mutable.HashSet[Int]()

    for(arr<-arrSet){
      if(count==0){
        for(i<-arr){
          set.add(i)
        }
      }else{
        set={
          val tempSet = new mutable.HashSet[Int]()
          for(i<-arr){
            if(set.contains(i)){
              tempSet.add(i)
            }
          }
          tempSet
        }
      }
      count+=1
    }
    set
  }

  def intersection(intSet: mutable.HashSet[Int], numbers: mutable.TreeSet[Int]): Int = {
    for(i<-numbers){
      if(intSet.contains(i)){
        return i
      }
    }
    return  -1
  }
}

object Main extends App {
  val numbers = new mutable.TreeSet[Int]()
  for (i <- 0 to 9) {
    numbers += i
  }
  val count = StdIn.readInt()
  val yesSet = new mutable.HashSet[Array[Int]]()
  for (_ <- 1 to count) {
    val input = StdIn.readLine().split(" ")
    val array = input.toList.slice(0, 4).toArray.map(i => i.toInt)
    if (input.last == "YES") {
      yesSet.add(array)
    }
    else {
      for (i <- array) {
        numbers.remove(i)
      }
    }
  }
  if (yesSet.size > 0) {
    println(Sub.intersection(Sub.intersection(yesSet), numbers))
  } else {
    println(numbers.toArray.apply(0))
  }

}
0