結果

問題 No.13 囲みたい!
ユーザー バカらっくバカらっく
提出日時 2019-08-31 13:41:58
言語 Kotlin
(1.9.23)
結果
RE  
実行時間 -
コード長 1,879 bytes
コンパイル時間 16,921 ms
コンパイル使用メモリ 450,128 KB
実行使用メモリ 62,372 KB
最終ジャッジ日時 2024-05-03 14:12:13
合計ジャッジ時間 21,310 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 303 ms
51,848 KB
testcase_01 AC 306 ms
52,000 KB
testcase_02 AC 307 ms
51,892 KB
testcase_03 RE -
testcase_04 AC 402 ms
53,280 KB
testcase_05 RE -
testcase_06 AC 415 ms
53,272 KB
testcase_07 AC 474 ms
62,372 KB
testcase_08 AC 471 ms
61,000 KB
testcase_09 AC 500 ms
59,116 KB
testcase_10 AC 350 ms
52,952 KB
testcase_11 AC 463 ms
59,096 KB
testcase_12 AC 326 ms
52,284 KB
testcase_13 AC 419 ms
58,076 KB
testcase_14 AC 417 ms
58,276 KB
testcase_15 AC 318 ms
52,104 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>){
         ^
Main.kt:33:9: warning: variable 'num' is never used
    val num = map[y][x]
        ^

ソースコード

diff #

fun main(args: Array<String>){
    val (a1, a2) = readLine()!!.split(" ").map { it.toInt() }
    w = a1
    h = a2

    for(i in 1..h) {
        map.add(readLine()!!.trim().split(" ").map { it.toInt() }.toTypedArray())
        flags.add((1..w).map { false }.toTypedArray())
    }

    for(i in 0..h-1) {
        for(j in 0..w-1) {
            val history = mutableMapOf<Int, MutableMap<Int, Boolean>>()
            history[i] = mutableMapOf()
            history[i]!![j] = true
            if(getAns(i, j, -1, -1, history)) {
                println("possible")
                return
            }
        }
    }
    println("impossible")
}
var w = 0
var h = 0
val map = mutableListOf<Array<Int>>()
var flags = mutableListOf<Array<Boolean>>()
fun getAns(y:Int, x:Int, prevY:Int, prevX:Int, history:MutableMap<Int, MutableMap<Int, Boolean>>): Boolean {
    if(flags[y][x]) {
        return false
    }
    flags[y][x] = true
    val num = map[y][x]
    for(i in Math.max(0, y-1)..Math.min(h-1, y+1)) {
        for(j in Math.max(0, x-1)..Math.min(w-1, x+1)) {
            if(i!=y && j!=x) {
                continue
            }
            if(i==y&&j==x) {
                continue
            }
            if(i ==prevY && j ==prevX) {
                continue
            }
            if(map[i][j] != map[y][x]) {
                continue
            }
            if(history.containsKey(i) && history[i]!!.containsKey(j)) {
                return true
            }
            if(!history.containsKey(i)) {
                history[i] = mutableMapOf()
            }
            history[i]!![j] = true
            val ret = getAns(i, j, y, x, history)
            history[i]!!.remove(j)
            if(history[i]!!.size == 0) {
                history.remove(i)
            }
            if(ret) {
                return true
            }
        }
    }
    return false
}
0