結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2019-08-31 18:06:12 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 1,028 ms / 5,000 ms |
| コード長 | 2,216 bytes |
| コンパイル時間 | 13,502 ms |
| コンパイル使用メモリ | 446,764 KB |
| 実行使用メモリ | 92,312 KB |
| 最終ジャッジ日時 | 2024-11-25 01:22:00 |
| 合計ジャッジ時間 | 22,318 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used
fun main(args: Array<String>){
^
Main.kt:46:9: warning: variable 'num' is never used
val num = map[y][x]
^
ソースコード
import java.util.*
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
stk.push(Task(i ,j, -1, -1, history))
while (stk.isNotEmpty()) {
val tsk = stk.pop()
getAns(tsk.y, tsk.x, tsk.prevY, tsk.prevX, tsk.history)
}
}
}
if(ans) {
println("possible")
} else {
println("impossible")
}
}
class Task(val y: Int, val x: Int, val prevY: Int, val prevX: Int, val history: MutableMap<Int, MutableMap<Int, Boolean>>)
val stk = Stack<Task>()
var w = 0
var h = 0
var ans = false
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>>) {
if(ans) {
return
}
if(flags[y][x]) {
return
}
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)) {
ans = true
return
}
val subHistory = mutableMapOf<Int, MutableMap<Int, Boolean>>()
history.forEach { subHistory[it.key] = it.value.toMutableMap() }
if(!subHistory.containsKey(i)) {
subHistory[i] = mutableMapOf()
}
subHistory[i]!![j] = true
stk.push(Task(i, j, y, x, subHistory))
}
}
}
バカらっく