結果
問題 | No.133 カードゲーム |
ユーザー | apprec |
提出日時 | 2020-05-30 15:54:25 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 367 ms / 5,000 ms |
コード長 | 2,005 bytes |
コンパイル時間 | 14,864 ms |
コンパイル使用メモリ | 423,820 KB |
実行使用メモリ | 58,776 KB |
最終ジャッジ日時 | 2023-08-07 14:30:32 |
合計ジャッジ時間 | 25,090 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 360 ms
58,508 KB |
testcase_01 | AC | 356 ms
58,392 KB |
testcase_02 | AC | 355 ms
58,128 KB |
testcase_03 | AC | 359 ms
58,060 KB |
testcase_04 | AC | 360 ms
58,216 KB |
testcase_05 | AC | 358 ms
58,576 KB |
testcase_06 | AC | 359 ms
58,384 KB |
testcase_07 | AC | 361 ms
58,344 KB |
testcase_08 | AC | 363 ms
58,188 KB |
testcase_09 | AC | 359 ms
58,776 KB |
testcase_10 | AC | 361 ms
58,488 KB |
testcase_11 | AC | 358 ms
58,024 KB |
testcase_12 | AC | 363 ms
58,180 KB |
testcase_13 | AC | 367 ms
58,124 KB |
testcase_14 | AC | 362 ms
58,140 KB |
testcase_15 | AC | 362 ms
58,356 KB |
testcase_16 | AC | 365 ms
58,652 KB |
testcase_17 | AC | 359 ms
58,296 KB |
testcase_18 | AC | 357 ms
58,152 KB |
testcase_19 | AC | 355 ms
58,172 KB |
testcase_20 | AC | 357 ms
58,188 KB |
testcase_21 | AC | 358 ms
58,068 KB |
testcase_22 | AC | 361 ms
58,164 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() ^
ソースコード
//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)) }