結果

問題 No.43 野球の試合
ユーザー バカらっくバカらっく
提出日時 2019-09-08 01:52:21
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,654 bytes
コンパイル時間 17,875 ms
コンパイル使用メモリ 428,568 KB
実行使用メモリ 56,284 KB
最終ジャッジ日時 2023-09-09 22:20:49
合計ジャッジ時間 21,981 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 298 ms
56,084 KB
testcase_01 AC 299 ms
55,984 KB
testcase_02 AC 300 ms
56,152 KB
testcase_03 AC 298 ms
56,128 KB
testcase_04 AC 301 ms
56,284 KB
testcase_05 AC 306 ms
56,132 KB
testcase_06 AC 303 ms
56,120 KB
testcase_07 AC 296 ms
56,112 KB
testcase_08 AC 299 ms
56,104 KB
testcase_09 AC 298 ms
56,060 KB
testcase_10 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^
Main.kt:22:68: warning: unnecessary non-null assertion (!!) on a non-null receiver of type List<Int>
        val w = target.sortedBy { taisen[it].count { it == 'o' }  }!!.first()
                                                                   ^

ソースコード

diff #

import java.util.*

fun main(arr:Array<String>) {
    val teamCount = readLine()!!.toInt()
    val taisen = (1..teamCount).map { readLine()!!.map { it }.toTypedArray() }.toTypedArray()
    taisen[0].indices.forEach {
        if(it > 0) {
            if(taisen[0][it] == '-') {
                taisen[0][it] = 'o'
                taisen[it][0] = 'x'
            }
        }
    }
    val queue = PriorityQueue<Int>(kotlin.Comparator { a, b -> taisen[b].count { it == 'o' }.compareTo(taisen[a].count{ it == 'o'}) })
    queue.addAll(1..(teamCount-1))
    while (queue.isNotEmpty()) {
        val l = queue.poll()
        val target = (1..teamCount - 1).filter { taisen[l][it] == '-' }
        if(target.isEmpty()) {
            continue
        }
        val w = target.sortedBy { taisen[it].count { it == 'o' }  }!!.first()
        taisen[l][w] = 'x'
        taisen[w][l] = 'o'
        queue.add(l)
    }
    val ans = taisen.map { it.count { it == 'o' } }.distinct().sortedDescending().indexOf(taisen[0].count { it == 'o' }) + 1
    println(ans)
}

val dic = mutableMapOf<Int, MutableMap<Long, Long>>()
val coins = (1..9).map { 111111 * it }.reversed().toTypedArray()
fun getAns(idx:Int, target :Long):Long {
    if(target < coins.last() ) {
        return 1
    }
    if(idx > coins.lastIndex) {
        return 1
    }
    if(!dic.containsKey(idx)) {
        dic[idx] = mutableMapOf()
    }
    dic[idx]!![target]?.let { return it }
    var ans = 0.toLong()
    for(i in 0..target) {
        if(i*coins[idx] > target) {
            break
        }
        ans += getAns(idx + 1, target - i*coins[idx])
    }
    dic[idx]!![target] = ans
    return ans
}
0