結果

問題 No.5017 Tool-assisted Shooting
ユーザー エセ賢者エセ賢者
提出日時 2023-08-03 13:33:53
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 492 ms / 2,000 ms
コード長 3,869 bytes
コンパイル時間 18,679 ms
コンパイル使用メモリ 435,564 KB
実行使用メモリ 73,316 KB
スコア 5,854
平均クエリ数 362.34
最終ジャッジ日時 2023-08-03 13:35:00
合計ジャッジ時間 62,890 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 379 ms
71,076 KB
testcase_01 AC 407 ms
70,912 KB
testcase_02 AC 363 ms
69,184 KB
testcase_03 AC 398 ms
71,420 KB
testcase_04 AC 449 ms
71,948 KB
testcase_05 AC 379 ms
71,708 KB
testcase_06 AC 399 ms
71,712 KB
testcase_07 AC 380 ms
69,488 KB
testcase_08 AC 388 ms
71,884 KB
testcase_09 AC 403 ms
71,224 KB
testcase_10 AC 400 ms
68,816 KB
testcase_11 AC 383 ms
71,600 KB
testcase_12 AC 397 ms
70,936 KB
testcase_13 AC 390 ms
69,488 KB
testcase_14 AC 435 ms
71,936 KB
testcase_15 AC 380 ms
69,084 KB
testcase_16 AC 382 ms
69,548 KB
testcase_17 AC 416 ms
71,732 KB
testcase_18 AC 359 ms
68,900 KB
testcase_19 AC 468 ms
73,068 KB
testcase_20 AC 418 ms
71,776 KB
testcase_21 AC 358 ms
69,468 KB
testcase_22 AC 361 ms
69,420 KB
testcase_23 AC 409 ms
71,756 KB
testcase_24 AC 375 ms
69,248 KB
testcase_25 AC 364 ms
69,488 KB
testcase_26 AC 418 ms
72,444 KB
testcase_27 AC 371 ms
69,208 KB
testcase_28 AC 400 ms
71,276 KB
testcase_29 AC 357 ms
69,260 KB
testcase_30 AC 386 ms
71,628 KB
testcase_31 AC 397 ms
69,620 KB
testcase_32 AC 372 ms
71,660 KB
testcase_33 AC 362 ms
69,056 KB
testcase_34 AC 395 ms
69,392 KB
testcase_35 AC 398 ms
71,592 KB
testcase_36 AC 369 ms
69,548 KB
testcase_37 AC 418 ms
71,196 KB
testcase_38 AC 360 ms
69,456 KB
testcase_39 AC 396 ms
71,216 KB
testcase_40 AC 383 ms
69,332 KB
testcase_41 AC 370 ms
69,204 KB
testcase_42 AC 401 ms
71,136 KB
testcase_43 AC 387 ms
69,264 KB
testcase_44 AC 374 ms
69,040 KB
testcase_45 AC 475 ms
73,316 KB
testcase_46 AC 381 ms
69,196 KB
testcase_47 AC 422 ms
71,984 KB
testcase_48 AC 381 ms
69,324 KB
testcase_49 AC 450 ms
72,892 KB
testcase_50 AC 357 ms
68,848 KB
testcase_51 AC 402 ms
69,080 KB
testcase_52 AC 400 ms
71,500 KB
testcase_53 AC 461 ms
72,248 KB
testcase_54 AC 406 ms
71,936 KB
testcase_55 AC 366 ms
69,216 KB
testcase_56 AC 426 ms
71,364 KB
testcase_57 AC 393 ms
71,356 KB
testcase_58 AC 409 ms
71,796 KB
testcase_59 AC 388 ms
69,360 KB
testcase_60 AC 370 ms
71,328 KB
testcase_61 AC 399 ms
71,136 KB
testcase_62 AC 417 ms
71,108 KB
testcase_63 AC 372 ms
69,468 KB
testcase_64 AC 368 ms
69,464 KB
testcase_65 AC 393 ms
71,636 KB
testcase_66 AC 367 ms
69,112 KB
testcase_67 AC 379 ms
69,028 KB
testcase_68 AC 423 ms
71,940 KB
testcase_69 AC 364 ms
69,504 KB
testcase_70 AC 392 ms
71,492 KB
testcase_71 AC 434 ms
71,776 KB
testcase_72 AC 395 ms
71,640 KB
testcase_73 AC 407 ms
72,020 KB
testcase_74 AC 360 ms
69,000 KB
testcase_75 AC 366 ms
71,440 KB
testcase_76 AC 410 ms
71,132 KB
testcase_77 AC 379 ms
68,888 KB
testcase_78 AC 366 ms
69,576 KB
testcase_79 AC 492 ms
72,400 KB
testcase_80 AC 441 ms
72,544 KB
testcase_81 AC 396 ms
71,636 KB
testcase_82 AC 387 ms
68,792 KB
testcase_83 AC 373 ms
69,328 KB
testcase_84 AC 394 ms
71,796 KB
testcase_85 AC 388 ms
71,236 KB
testcase_86 AC 408 ms
72,256 KB
testcase_87 AC 389 ms
69,236 KB
testcase_88 AC 397 ms
71,308 KB
testcase_89 AC 363 ms
69,464 KB
testcase_90 AC 413 ms
70,864 KB
testcase_91 AC 402 ms
71,792 KB
testcase_92 AC 396 ms
71,004 KB
testcase_93 AC 385 ms
68,964 KB
testcase_94 AC 372 ms
69,368 KB
testcase_95 AC 405 ms
71,636 KB
testcase_96 AC 379 ms
68,764 KB
testcase_97 AC 374 ms
71,488 KB
testcase_98 AC 384 ms
71,560 KB
testcase_99 AC 396 ms
71,168 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:10:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:46:59: warning: unnecessary non-null assertion (!!) on a non-null receiver of type GameState
        gameState = nextSteps.minBy { it.evaluateScore() }!!
                                                          ^
Main.kt:118:23: warning: 'sumBy((T) -> Int): Int' is deprecated. Use sumOf instead.
            enemyList.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<GameState>()
        for (move in validMove) {
            when (move) {
                "S" -> {
                    val state = gameState.copy()
                    state.nextTurnS()
                    nextSteps.add(state)
                }

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

                "L" -> {
                    val state = gameState.copy()
                    state.nextTurnL()
                    nextSteps.add(state)
                }
            }
        }
        gameState = nextSteps.minBy { it.evaluateScore() }!!
    }
}

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 = Own(own.x, own.y + 1)
        println("S")
        val first = enemyList.firstOrNull { it.isAlive() && it.x == own.x && it.y > own.y } ?: return
        first.hit(own.level())
        if (!first.isAlive()) {
            own.defeat(first.p)
        }
    }

    fun nextTurnR() {
        turn++
        own = Own(own.x + 1, own.y + 1)
        println("R")
        val first = enemyList.firstOrNull { it.isAlive() && it.x == own.x && it.y > own.y } ?: return
        first.hit(own.level())
        if (!first.isAlive()) {
            own.defeat(first.p)
        }
    }

    fun nextTurnL() {
        turn++
        own = Own(own.x - 1, own.y + 1)
        println("L")
        val first = enemyList.firstOrNull { it.isAlive() && it.x == own.x && it.y > own.y } ?: 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
        gameState.turn = turn
        return gameState
    }

    fun evaluateScore(): Int {
        val collision = enemyList.filter { it.x == own.x && it.y == own.y }
        return if (collision.isEmpty()) {
            enemyList.sumBy { it.h }
        } else {
            Int.MAX_VALUE
        }
    }
}

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
    }
}
0