結果

問題 No.133 カードゲーム
ユーザー apprecapprec
提出日時 2020-05-30 15:54:25
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 356 ms / 5,000 ms
コード長 2,005 bytes
コンパイル時間 15,378 ms
コンパイル使用メモリ 446,800 KB
実行使用メモリ 56,540 KB
最終ジャッジ日時 2024-04-25 08:14:11
合計ジャッジ時間 25,512 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 347 ms
56,408 KB
testcase_01 AC 354 ms
56,204 KB
testcase_02 AC 347 ms
56,184 KB
testcase_03 AC 355 ms
56,240 KB
testcase_04 AC 347 ms
56,408 KB
testcase_05 AC 347 ms
56,288 KB
testcase_06 AC 349 ms
56,436 KB
testcase_07 AC 344 ms
56,180 KB
testcase_08 AC 345 ms
56,380 KB
testcase_09 AC 344 ms
56,396 KB
testcase_10 AC 346 ms
56,172 KB
testcase_11 AC 356 ms
56,276 KB
testcase_12 AC 348 ms
56,192 KB
testcase_13 AC 341 ms
56,324 KB
testcase_14 AC 339 ms
56,496 KB
testcase_15 AC 340 ms
56,300 KB
testcase_16 AC 352 ms
56,280 KB
testcase_17 AC 344 ms
56,176 KB
testcase_18 AC 346 ms
56,440 KB
testcase_19 AC 342 ms
56,276 KB
testcase_20 AC 341 ms
56,304 KB
testcase_21 AC 342 ms
56,540 KB
testcase_22 AC 349 ms
56,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:67:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:68:9: warning: variable 'N' is never used
    val N = readInt()
        ^

ソースコード

diff #

//package Qy
import java.util.*
import java.math.*
import java.lang.Math.*
import java.nio.IntBuffer

private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = {readLine()!!.toInt()}
private val readLong: ()->Long = {readLine()!!.toLong()}
private val readIntArray: ()->IntArray = {readLine()!!.split(' ').map{it.toInt()}.toIntArray()}
private val readLongArray: ()->LongArray = {readLine()!!.split(' ').map{it.toLong()}.toLongArray()}
private val errPrintln: (String)->Unit = {msg -> System.err.println(msg)}
private val MOD = 1e9.toLong()+7
private val INF = Int.MAX_VALUE/2
private val LINF = Long.MAX_VALUE/2


private fun permutation(A: IntArray): List<IntArray> {
    val ary = A.sorted()
    val N = ary.size
    val used = BooleanArray(N){false}
    val hm = HashMap<IntBuffer, IntArray>()
    val ptn = ArrayList<Int>(0)
    fun dfs(n: Int) {
        if (n >= N) {
            val value = ptn.toIntArray()
            val key = IntBuffer.wrap(value)
            hm[key] = value
        }
        for (i in 0 until N) {
            if (used[i]) continue
            used[i] = true
            ptn.add(ary[i])
            dfs(n+1)
            ptn.removeAt(ptn.lastIndex)
            used[i] = false
        }
    }
    dfs(0)
    val res = ArrayList<IntArray>()
    for (key in hm.keys.sorted()) {
        res.add(hm[key]!!)
    }
    return res.toList()
}


private fun solveY(A: IntArray, B: IntArray): Double {
    val a = A.sorted()
    val bPatterns = permutation(B)

    var aWin = 0
    for (bPattern in bPatterns) {
        var aw = 0; var bw = 0; var draw = 0
        a.forEachIndexed { i, v ->
            if (v > bPattern[i]) aw++
            else if (v < bPattern[i]) bw++
            else draw++
        }
        if (aw > bw) aWin++
    }

    return aWin.toDouble() / bPatterns.size
}


fun main(args: Array<String>) {
    val N = readInt()
    val A = readIntArray()
    val B = readIntArray()

    val ans = solveY(A, B)

    println("%.8f".format(ans))
}
0