結果
| 問題 | 
                            No.233 めぐるはめぐる (3)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-01-29 02:09:41 | 
| 言語 | Nim  (2.2.0)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 881 bytes | 
| コンパイル時間 | 2,459 ms | 
| コンパイル使用メモリ | 63,784 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-01 11:05:23 | 
| 合計ジャッジ時間 | 7,040 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | RE * 3 | 
| other | RE * 11 | 
ソースコード
import sequtils
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': return
    result = 10 * result + k.ord - '0'.ord
const dxdy4 :seq[tuple[x,y:int]] = @[(0,1),(1,0),(0,-1),(-1,0)]
let w = scan()
let h = scan()
var M = newSeqWith(w,newSeqUninitialized[int](h))
for y in 0..<h:
  for x in 0..<w:
    M[x][y] = scan()
var already = newSeqWith(w,newSeq[bool](h))
proc dfs(x,y,px,py,m:int) =
  already[x][y] = true
  for d in dxdy4:
    let nx = x + d.x
    let ny = y + d.y
    if nx < 0 or ny < 0 or nx >= w or ny >= h : continue
    if nx == px and ny == py : continue
    if M[nx][ny] != m : continue
    if already[nx][ny] : quit "possible",0
    dfs(nx,ny,x,y,m)
for x in 0..<w:
  for y in 0..<h:
    if not already[x][y] : dfs(x,y,-1,-1,M[x][y])
echo "impossible"