結果

問題 No.5017 Tool-assisted Shooting
ユーザー エセ賢者エセ賢者
提出日時 2023-08-03 13:52:14
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 859 ms / 2,000 ms
コード長 3,954 bytes
コンパイル時間 20,526 ms
コンパイル使用メモリ 430,176 KB
実行使用メモリ 75,344 KB
スコア 262,795
平均クエリ数 814.46
最終ジャッジ日時 2023-08-03 13:53:59
合計ジャッジ時間 94,592 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 837 ms
73,812 KB
testcase_01 AC 506 ms
74,012 KB
testcase_02 AC 498 ms
73,536 KB
testcase_03 AC 833 ms
73,392 KB
testcase_04 AC 782 ms
74,012 KB
testcase_05 AC 515 ms
73,080 KB
testcase_06 AC 766 ms
73,276 KB
testcase_07 AC 596 ms
73,712 KB
testcase_08 AC 763 ms
73,348 KB
testcase_09 AC 813 ms
74,052 KB
testcase_10 AC 752 ms
74,036 KB
testcase_11 AC 736 ms
73,348 KB
testcase_12 AC 778 ms
74,256 KB
testcase_13 AC 817 ms
74,080 KB
testcase_14 AC 649 ms
73,280 KB
testcase_15 AC 842 ms
73,520 KB
testcase_16 AC 767 ms
73,572 KB
testcase_17 AC 586 ms
73,892 KB
testcase_18 AC 452 ms
73,576 KB
testcase_19 AC 734 ms
73,924 KB
testcase_20 AC 688 ms
74,320 KB
testcase_21 AC 762 ms
73,352 KB
testcase_22 AC 773 ms
74,248 KB
testcase_23 AC 753 ms
73,528 KB
testcase_24 AC 720 ms
74,416 KB
testcase_25 AC 802 ms
73,768 KB
testcase_26 AC 747 ms
73,616 KB
testcase_27 AC 757 ms
74,704 KB
testcase_28 AC 550 ms
73,316 KB
testcase_29 AC 745 ms
73,900 KB
testcase_30 AC 849 ms
72,968 KB
testcase_31 AC 572 ms
73,356 KB
testcase_32 AC 751 ms
74,672 KB
testcase_33 AC 681 ms
73,752 KB
testcase_34 AC 588 ms
74,916 KB
testcase_35 AC 792 ms
73,992 KB
testcase_36 AC 793 ms
74,264 KB
testcase_37 AC 812 ms
74,456 KB
testcase_38 AC 730 ms
73,468 KB
testcase_39 AC 702 ms
73,744 KB
testcase_40 AC 590 ms
73,760 KB
testcase_41 AC 697 ms
73,672 KB
testcase_42 AC 771 ms
73,436 KB
testcase_43 AC 772 ms
74,584 KB
testcase_44 AC 581 ms
73,848 KB
testcase_45 AC 841 ms
73,976 KB
testcase_46 AC 729 ms
74,296 KB
testcase_47 AC 836 ms
74,244 KB
testcase_48 AC 782 ms
73,364 KB
testcase_49 AC 578 ms
74,732 KB
testcase_50 AC 778 ms
73,400 KB
testcase_51 AC 710 ms
74,388 KB
testcase_52 AC 711 ms
73,060 KB
testcase_53 AC 617 ms
73,844 KB
testcase_54 AC 612 ms
73,912 KB
testcase_55 AC 748 ms
74,852 KB
testcase_56 AC 725 ms
73,416 KB
testcase_57 AC 694 ms
74,336 KB
testcase_58 AC 824 ms
74,720 KB
testcase_59 AC 859 ms
73,420 KB
testcase_60 AC 445 ms
73,236 KB
testcase_61 AC 751 ms
74,828 KB
testcase_62 AC 688 ms
74,076 KB
testcase_63 AC 367 ms
69,296 KB
testcase_64 AC 628 ms
73,028 KB
testcase_65 AC 460 ms
72,752 KB
testcase_66 AC 820 ms
74,432 KB
testcase_67 AC 811 ms
73,288 KB
testcase_68 AC 385 ms
72,116 KB
testcase_69 AC 848 ms
73,720 KB
testcase_70 AC 816 ms
73,396 KB
testcase_71 AC 574 ms
74,320 KB
testcase_72 AC 764 ms
74,020 KB
testcase_73 AC 596 ms
74,188 KB
testcase_74 AC 777 ms
74,796 KB
testcase_75 AC 813 ms
74,212 KB
testcase_76 AC 708 ms
73,932 KB
testcase_77 AC 745 ms
73,384 KB
testcase_78 AC 550 ms
73,352 KB
testcase_79 AC 443 ms
72,112 KB
testcase_80 AC 543 ms
73,848 KB
testcase_81 AC 848 ms
74,524 KB
testcase_82 AC 743 ms
74,380 KB
testcase_83 AC 522 ms
73,780 KB
testcase_84 AC 768 ms
73,012 KB
testcase_85 AC 740 ms
75,344 KB
testcase_86 AC 758 ms
73,764 KB
testcase_87 AC 821 ms
73,608 KB
testcase_88 AC 747 ms
73,440 KB
testcase_89 AC 452 ms
72,816 KB
testcase_90 AC 806 ms
74,060 KB
testcase_91 AC 586 ms
73,448 KB
testcase_92 AC 684 ms
73,700 KB
testcase_93 AC 795 ms
73,644 KB
testcase_94 AC 835 ms
74,028 KB
testcase_95 AC 724 ms
73,356 KB
testcase_96 AC 583 ms
73,844 KB
testcase_97 AC 758 ms
73,088 KB
testcase_98 AC 572 ms
73,552 KB
testcase_99 AC 790 ms
73,872 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:10:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:46:69: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Pair<String, GameState>
        val minState = nextSteps.minBy { it.second.evaluateScore() }!!
                                                                    ^
Main.kt:117: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<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.minBy { it.second.evaluateScore() }!!
        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 = Own(own.x, own.y + 1)
        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)
        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)
        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 || it.y == own.y + 1) }
        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