結果
| 問題 | No.13 囲みたい! |
| コンテスト | |
| ユーザー |
wotsushi
|
| 提出日時 | 2017-05-24 21:48:51 |
| 言語 | Ruby (3.4.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 542 bytes |
| 記録 | |
| コンパイル時間 | 35 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 19,328 KB |
| 最終ジャッジ日時 | 2024-09-19 18:36:39 |
| 合計ジャッジ時間 | 2,246 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 RE * 2 |
コンパイルメッセージ
Syntax OK
ソースコード
W, H = gets.split.map(&:to_i)
M = (1..H).map {gets.split.map(&:to_i)}
DP = Array.new(H) {Array.new(W, false)}
def f(i, j, p, q)
if not i.between?(0, H - 1) or not j.between?(0, W - 1) or M[i][j] != M[p][q]
false
elsif DP[i][j]
true
else
DP[i][j] = true
[[i, j + 1], [i + 1, j], [i, j - 1], [i - 1, j]].any? {|a, b| [a, b] != [p, q] and f(a, b, i, j)}
end
end
ans = if (0...H).to_a.product((0...W).to_a).any? {|i, j| not DP[i][j] and f(i, j, i, j)}
"possible"
else
"impossible"
end
puts ans
wotsushi