結果
| 問題 |
No.133 カードゲーム
|
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2019-10-03 10:33:39 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 304 ms / 5,000 ms |
| コード長 | 1,049 bytes |
| コンパイル時間 | 14,110 ms |
| コンパイル使用メモリ | 443,636 KB |
| 実行使用メモリ | 57,292 KB |
| 最終ジャッジ日時 | 2024-10-03 06:08:39 |
| 合計ジャッジ時間 | 18,738 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args:Array<String>) {
^
ソースコード
fun main(args:Array<String>) {
val turnCount = readLine()!!.toInt()
val cards1 = readLine()!!.split(" ").map { it.toInt() }
val cards2 = readLine()!!.split(" ").map { it.toInt() }
val ans = getResult(cards1, cards2, 0, turnCount).let { it.first / it.second.toDouble() }
println(ans)
}
fun getResult(myCards:List<Int>, otherCards:List<Int>, subTotal:Int, turnCount:Int):Pair<Int, Int> {
if(myCards.size == 0) {
return if(subTotal > (turnCount - subTotal)) 1 to 1 else 0 to 1
}
var winCount = 0 to 0
for(i in myCards.indices) {
val newMyCards = myCards.withIndex().filter { it.index != i }.map { it.value }
for(j in otherCards.indices) {
val newOtherCards = otherCards.withIndex().filter { it.index != j }.map { it.value }
val ret = getResult(newMyCards, newOtherCards, if (myCards[i] > otherCards[j]) subTotal + 1 else subTotal, turnCount)
winCount = winCount.first + ret.first to winCount.second + ret.second
}
}
return winCount
}
バカらっく