結果

問題 No.447 ゆきこーだーの雨と雪 (2)
ユーザー HujiLeeHujiLee
提出日時 2016-11-26 11:52:58
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,594 ms / 2,000 ms
コード長 4,644 bytes
コンパイル時間 12,004 ms
コンパイル使用メモリ 263,680 KB
実行使用メモリ 75,408 KB
最終ジャッジ日時 2023-09-12 07:42:57
合計ジャッジ時間 50,369 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 961 ms
62,704 KB
testcase_01 AC 950 ms
62,828 KB
testcase_02 AC 958 ms
62,968 KB
testcase_03 AC 1,215 ms
65,140 KB
testcase_04 AC 1,139 ms
63,460 KB
testcase_05 AC 1,507 ms
68,224 KB
testcase_06 AC 1,498 ms
71,440 KB
testcase_07 AC 1,350 ms
65,620 KB
testcase_08 AC 1,365 ms
67,484 KB
testcase_09 AC 1,508 ms
69,520 KB
testcase_10 AC 1,215 ms
65,132 KB
testcase_11 AC 1,318 ms
65,360 KB
testcase_12 AC 1,316 ms
65,344 KB
testcase_13 AC 1,456 ms
67,748 KB
testcase_14 AC 1,485 ms
69,712 KB
testcase_15 AC 1,325 ms
65,704 KB
testcase_16 AC 1,255 ms
65,576 KB
testcase_17 AC 1,280 ms
65,196 KB
testcase_18 AC 1,093 ms
63,660 KB
testcase_19 AC 1,594 ms
75,408 KB
testcase_20 AC 1,519 ms
69,784 KB
testcase_21 AC 1,311 ms
65,552 KB
testcase_22 AC 1,256 ms
65,172 KB
testcase_23 AC 1,425 ms
65,396 KB
testcase_24 AC 1,436 ms
69,536 KB
testcase_25 AC 1,469 ms
69,444 KB
testcase_26 AC 1,425 ms
67,824 KB
testcase_27 AC 1,450 ms
67,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

/**
  * Created by Administrator on 2016/11/25 0025.
  */


class Question($star: Int) {
  val star = $star
  private[this] var _countSolved: Int = 0

  def countSolved: Int = _countSolved

  private def countSolved_=(value: Int): Unit = {
    _countSolved = value
  }


  def beSolved: Int = {
    _countSolved += 1
    _countSolved
  }

}

class User($name: String) {
  private var totalScore = -1
  private var mapQuesIndex2Score = new mutable.HashMap[Int,Double]()

  def toString(problems: mutable.HashMap[Int, Question]): String = {
    def singleQustionCalc(question: Question, solvedOrder: Int): Double = {
      math.floor(50 * question.star + (50 * question.star) / ((8 + 2 * solvedOrder) / 10.0))
    }

    if (totalScore == -1) {
      for(i<-problems.keys){
        if(mapQuesIndex2SolvedOrder.contains(i)){
          mapQuesIndex2Score+=(i->singleQustionCalc(problems(i),mapQuesIndex2SolvedOrder(i)))
        }else{
          mapQuesIndex2Score+=(i->0.0)
        }
      }
      totalScore = {
        var $ = 0.0
        for(i<-mapQuesIndex2Score.keys){
          $+=mapQuesIndex2Score(i)
        }
        $.toInt
      }
    }
    var result = {
      var $ = ""
      for(i<- 0 until mapQuesIndex2Score.size){
        if(i>0){
          $+=" "
        }
        $+=mapQuesIndex2Score(i).toInt
      }
      $+=(" "+totalScore)
      $
    }
    result
  }

  def getTotal:Int={
    require(totalScore>=0)
    return totalScore
  }

  private var order = 0
  val name = $name
  private var mapQuesIndex2SolvedOrder = new mutable.HashMap[Int, Int]()

  def setOrder(int: Int): User = {
    this.order = int
    this
  }
  def getOrder:Int=order

  def solve(index: Int, solvedOrder: Int): User = {
    mapQuesIndex2SolvedOrder += (index -> solvedOrder)
    this
  }
}

object Users {
  /**
    * 0->Question1{star 1;2 men solved me}
    */
  private var problemsIndex2Question = new mutable.HashMap[Int, Question]()
  private var users = new mutable.LinkedHashMap[String, User]()
  private var usersList:List[(String, User)] = null

  def initStars(ints: Array[Int]): Users.type = {
    for (i <- ints.indices) {
      problemsIndex2Question += (i -> new Question(ints(i)))
    }
    return this
  }

  private def char2Index(chars: String): Int = chars.charAt(0) - 'A'

  def whoSolvedWhich(name: String, problem: String): Users.type = {
    val proIndex = char2Index(problem)
    if (problemsIndex2Question.contains(proIndex)) {
      problemsIndex2Question(proIndex).beSolved
    } else {
      //不可能啊 应该都在
      throw new Exception("I'll never show")
    }
    if (users.contains(name)) {
      users(name).solve(proIndex, problemsIndex2Question(proIndex).countSolved)
    } else {
      users.+=(name -> new User(name).solve(proIndex, problemsIndex2Question(proIndex).countSolved))
    }
    return this
  }

  def setUserOrder(name: String, order: Int): Users.type = {
    require(users.contains(name), "这个函数必须在whoSolvedWhich后执行")
    users(name).setOrder(order)
    return this
  }

  def sortUsers: Users.type ={
    usersList = users.toList
    for(i<-usersList){
      i._2.toString(problemsIndex2Question)
    }

    usersList = usersList.sortWith((a,b)=>{
      (a._2.getTotal>b._2.getTotal) match {
        case true=>true
        case false=>{
          (a._2.getTotal<b._2.getTotal) match {
            case true=>false
            case false=>a._2.getOrder<b._2.getOrder
          }
        }
      }
    })

    this
  }

  def printAfterSort={
    for(i<-usersList.indices){
      println(s"${i+1} ${usersList(i)._1} ${usersList(i)._2.toString(problemsIndex2Question)}")
    }
  }


}

/*object UserOrder{
  private var map = new mutable.HashMap[String,Int]()
  def push(username:String): UserOrder.type ={
    if(!map.contains(username)){
      map+=(username->(map.size+1))
    }else{
      for(i<-map.keys if map(i) > map(username)){
        map(i)-=1
      }
      map(username) = map.size
    }
    return this
  }
  def getMap: mutable.Map[String, Int] = map
}*/

object Main extends App {
  //  val order = UserOrder
  val users = Users.initStars(
    {
      //noinspection ScalaUnusedSymbol
      val countQuestions = StdIn.readInt()
      StdIn.readLine().split(" ").map(x => x.toInt)
    }
  )

  val T = StdIn.readInt()


  for (i <- 1 to T) {
    /**
      * name=username
      * ques = "ABCD...."
      */
    val Array(name, ques) = StdIn.readLine().split(" ")
    Users.whoSolvedWhich(name, ques).setUserOrder(name, i)
    //    order.push(name)

  }
  users.sortUsers.printAfterSort


  print("")


}
0