結果

問題 No.5017 Tool-assisted Shooting
ユーザー エセ賢者エセ賢者
提出日時 2023-08-03 15:10:12
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,827 ms / 2,000 ms
コード長 4,669 bytes
コンパイル時間 18,415 ms
コンパイル使用メモリ 434,540 KB
実行使用メモリ 83,172 KB
スコア 1,064,522
平均クエリ数 852.28
最終ジャッジ日時 2023-08-03 15:13:00
合計ジャッジ時間 147,557 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,504 ms
80,168 KB
testcase_01 AC 488 ms
76,456 KB
testcase_02 AC 608 ms
78,796 KB
testcase_03 AC 1,317 ms
79,912 KB
testcase_04 AC 1,114 ms
81,696 KB
testcase_05 AC 1,155 ms
78,384 KB
testcase_06 AC 1,236 ms
81,076 KB
testcase_07 AC 1,235 ms
79,844 KB
testcase_08 AC 1,404 ms
78,752 KB
testcase_09 AC 1,414 ms
80,640 KB
testcase_10 AC 545 ms
77,476 KB
testcase_11 AC 1,206 ms
80,768 KB
testcase_12 AC 1,495 ms
81,984 KB
testcase_13 AC 1,323 ms
81,116 KB
testcase_14 AC 1,449 ms
81,512 KB
testcase_15 AC 1,187 ms
79,304 KB
testcase_16 AC 1,215 ms
78,396 KB
testcase_17 AC 1,416 ms
81,604 KB
testcase_18 AC 1,413 ms
81,632 KB
testcase_19 AC 1,415 ms
82,792 KB
testcase_20 AC 1,464 ms
79,536 KB
testcase_21 AC 1,317 ms
82,168 KB
testcase_22 AC 947 ms
80,188 KB
testcase_23 AC 776 ms
78,968 KB
testcase_24 AC 1,069 ms
81,132 KB
testcase_25 AC 1,703 ms
81,900 KB
testcase_26 AC 1,404 ms
77,952 KB
testcase_27 AC 1,528 ms
79,544 KB
testcase_28 AC 1,722 ms
78,724 KB
testcase_29 AC 1,181 ms
82,684 KB
testcase_30 AC 1,233 ms
82,572 KB
testcase_31 AC 1,321 ms
82,504 KB
testcase_32 AC 532 ms
78,944 KB
testcase_33 AC 1,228 ms
79,056 KB
testcase_34 AC 1,107 ms
79,228 KB
testcase_35 AC 1,219 ms
81,140 KB
testcase_36 AC 1,252 ms
81,656 KB
testcase_37 AC 1,557 ms
77,828 KB
testcase_38 AC 496 ms
75,868 KB
testcase_39 AC 1,200 ms
79,792 KB
testcase_40 AC 427 ms
73,520 KB
testcase_41 AC 1,377 ms
81,352 KB
testcase_42 AC 886 ms
79,308 KB
testcase_43 AC 1,235 ms
81,452 KB
testcase_44 AC 1,292 ms
81,080 KB
testcase_45 AC 1,465 ms
81,336 KB
testcase_46 AC 1,673 ms
81,252 KB
testcase_47 AC 1,116 ms
79,464 KB
testcase_48 AC 1,405 ms
82,036 KB
testcase_49 AC 1,129 ms
81,300 KB
testcase_50 AC 951 ms
80,912 KB
testcase_51 AC 1,370 ms
81,136 KB
testcase_52 AC 1,191 ms
81,160 KB
testcase_53 AC 1,269 ms
79,064 KB
testcase_54 AC 1,827 ms
79,884 KB
testcase_55 AC 1,450 ms
81,568 KB
testcase_56 AC 1,101 ms
80,208 KB
testcase_57 AC 1,080 ms
79,224 KB
testcase_58 AC 847 ms
80,016 KB
testcase_59 AC 1,315 ms
81,528 KB
testcase_60 AC 1,357 ms
81,532 KB
testcase_61 AC 447 ms
75,972 KB
testcase_62 AC 1,215 ms
78,964 KB
testcase_63 AC 825 ms
79,112 KB
testcase_64 AC 1,505 ms
81,304 KB
testcase_65 AC 1,558 ms
83,172 KB
testcase_66 AC 516 ms
74,996 KB
testcase_67 AC 482 ms
75,060 KB
testcase_68 AC 1,330 ms
81,464 KB
testcase_69 AC 1,491 ms
82,740 KB
testcase_70 AC 1,499 ms
80,772 KB
testcase_71 AC 450 ms
75,140 KB
testcase_72 AC 1,124 ms
79,324 KB
testcase_73 AC 811 ms
78,436 KB
testcase_74 AC 1,386 ms
80,816 KB
testcase_75 AC 1,329 ms
80,928 KB
testcase_76 AC 1,320 ms
81,472 KB
testcase_77 AC 1,339 ms
77,880 KB
testcase_78 AC 1,553 ms
78,636 KB
testcase_79 AC 1,482 ms
79,372 KB
testcase_80 AC 1,399 ms
78,496 KB
testcase_81 AC 1,198 ms
81,472 KB
testcase_82 AC 1,341 ms
82,436 KB
testcase_83 AC 1,099 ms
78,660 KB
testcase_84 AC 1,345 ms
82,352 KB
testcase_85 AC 1,378 ms
79,932 KB
testcase_86 AC 607 ms
77,884 KB
testcase_87 AC 1,676 ms
80,232 KB
testcase_88 AC 1,255 ms
81,288 KB
testcase_89 AC 685 ms
79,136 KB
testcase_90 AC 1,176 ms
80,952 KB
testcase_91 AC 1,553 ms
81,388 KB
testcase_92 AC 1,234 ms
78,100 KB
testcase_93 AC 664 ms
77,712 KB
testcase_94 AC 1,229 ms
80,712 KB
testcase_95 AC 988 ms
79,180 KB
testcase_96 AC 1,322 ms
80,808 KB
testcase_97 AC 1,277 ms
80,264 KB
testcase_98 AC 1,341 ms
78,876 KB
testcase_99 AC 1,115 ms
80,840 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:10:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:133:50: warning: 'sumBy((T) -> Int): Int' is deprecated. Use sumOf instead.
        return enemyList.filter { it.isAlive() }.sumBy { it.h }
                                                 ^

ソースコード

diff #

private fun next() = readLine()!!
private fun nextInt() = next().toInt()
private fun nextLong() = next().toLong()
private fun nextDouble() = next().toDouble()
private fun nextList() = next().split(" ")
private fun nextIntList() = next().split(" ").map { it.toInt() }.toIntArray()
private fun nextLongList() = next().split(" ").map { it.toLong() }.toLongArray()
private fun nextDoubleList() = next().split(" ").map { it.toDouble() }.toDoubleArray()

fun main(args: Array<String>) {
    var gameState = GameState()

    while (!gameState.isDone()) {
        val n = nextInt()
        if (n == -1) {
            return
        }
        for (i in 0 until n) {
            val hpx = nextIntList()
            gameState.addEnemy(hpx)
        }

        val validMove = gameState.validMove()
        val nextSteps = mutableListOf<Pair<String, GameState>>()
        for (move in validMove) {
            when (move) {
                "S" -> {
                    val state = gameState.copy()
                    state.nextTurnS()
                    nextSteps.add(Pair("S", state))
                }

                "R" -> {
                    val state = gameState.copy()
                    state.nextTurnR()
                    nextSteps.add(Pair("R", state))
                }

                "L" -> {
                    val state = gameState.copy()
                    state.nextTurnL()
                    nextSteps.add(Pair("L", state))
                }
            }
        }
        val minState =
            nextSteps.sortedWith(
                compareBy(
                    { pair -> pair.second.enemyList.count { it.isAlive() } },
                    { it.second.evaluateScore() })
            ).first()
        gameState = minState.second
        println(minState.first)
    }
}

class GameState {
    var enemyList = mutableListOf<Enemy>()
    var own = Own(12, 0)
    var turn = 0

    fun addEnemy(hpx: IntArray) {
        enemyList.add(Enemy(hpx[2], 59 + turn, hpx[0], hpx[1]))
    }

    fun isDone(): Boolean {
        return turn >= 1000
    }

    fun validMove(): Array<String> {
        val move = mutableListOf("S")
        if (enemyList.none { it.x == own.x + 1 && it.y == own.y }) {
            move.add("R")
        }
        if (enemyList.none { it.x == own.x - 1 && it.y == own.y }) {
            move.add("L")
        }
        return move.toTypedArray()
    }

    fun nextTurnS() {
        turn++
        own.up()
        val first =
            enemyList.filter { it.isAlive() && it.x == own.x && it.y > own.y }.sortedBy { it.y }.firstOrNull() ?: return
        first.hit(own.level())
        if (!first.isAlive()) {
            own.defeat(first.p)
        }
    }

    fun nextTurnR() {
        turn++
        own.up()
        own.right()
        val first =
            enemyList.filter { it.isAlive() && it.x == own.x && it.y > own.y }.sortedBy { it.y }.firstOrNull() ?: return
        first.hit(own.level())
        if (!first.isAlive()) {
            own.defeat(first.p)
        }
    }

    fun nextTurnL() {
        turn++
        own.up()
        own.left()
        val first =
            enemyList.filter { it.isAlive() && it.x == own.x && it.y > own.y }.sortedBy { it.y }.firstOrNull() ?: return
        first.hit(own.level())
        if (!first.isAlive()) {
            own.defeat(first.p)
        }
    }

    fun copy(): GameState {
        val gameState = GameState()
        gameState.enemyList = enemyList.map { Enemy(it.x, it.y, it.h, it.p) }.toMutableList()
        gameState.own = own.copy()
        gameState.turn = turn
        return gameState
    }

    fun evaluateScore(): Int {
        val collision = enemyList.filter { it.x == own.x && (it.y == own.y || it.y == own.y + 1) }
        val first = enemyList.filter { it.isAlive() && it.x == own.x && it.y > own.y }.sortedBy { it.y }.firstOrNull()
        if (collision.isNotEmpty()) {
            return Int.MAX_VALUE
        }
        if (first != null && first.h > (first.y - own.y) * own.level()) {
            return Int.MAX_VALUE
        }
        return enemyList.filter { it.isAlive() }.sumBy { it.h }
    }
}

class Enemy(var x: Int, var y: Int, var h: Int, var p: Int) {
    fun isAlive(): Boolean {
        return h > 0
    }

    fun hit(damage: Int) {
        h -= damage
    }
}

class Own(var x: Int, var y: Int) {
    var p = 100
    fun defeat(power: Int) {
        p += power
    }

    fun level(): Int {
        return p / 100
    }

    fun up() {
        y++
    }

    fun right() {
        x++
    }

    fun left() {
        x--
    }

    fun copy(): Own {
        val copy = Own(x, y)
        copy.p = p
        return copy
    }
}
0