結果

問題 No.24 数当てゲーム
コンテスト
ユーザー HujiLee
提出日時 2016-12-24 23:18:35
言語 Scala(Beta)
(3.8.1)
コンパイル:
scalac _filename_
実行:
java -cp .:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala3-library_3/3.8.1/scala3-library_3-3.8.1.jar:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala-library/3.8.1/scala-library-3.8.1.jar _class_
結果
AC  
実行時間 364 ms / 5,000 ms
コード長 1,428 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,821 ms
コンパイル使用メモリ 269,608 KB
実行使用メモリ 64,028 KB
最終ジャッジ日時 2026-03-09 14:59:53
合計ジャッジ時間 12,179 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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