結果

問題 No.13 囲みたい!
ユーザー 👑 hos.lyrichos.lyric
提出日時 2015-03-01 21:07:57
言語 Ruby
(3.3.0)
結果
AC  
実行時間 89 ms / 5,000 ms
コード長 313 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 11,456 KB
実行使用メモリ 15,836 KB
最終ジャッジ日時 2023-08-26 23:13:36
合計ジャッジ時間 2,283 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
15,284 KB
testcase_01 AC 75 ms
15,292 KB
testcase_02 AC 74 ms
15,296 KB
testcase_03 AC 89 ms
15,560 KB
testcase_04 AC 81 ms
15,800 KB
testcase_05 AC 85 ms
15,636 KB
testcase_06 AC 81 ms
15,836 KB
testcase_07 AC 85 ms
15,684 KB
testcase_08 AC 80 ms
15,660 KB
testcase_09 AC 79 ms
15,684 KB
testcase_10 AC 74 ms
15,168 KB
testcase_11 AC 78 ms
15,500 KB
testcase_12 AC 74 ms
15,168 KB
testcase_13 AC 76 ms
15,480 KB
testcase_14 AC 78 ms
15,360 KB
testcase_15 AC 76 ms
15,136 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def r u;u==$p[u]?u:$p[u]=r($p[u]);end
n,m=gets.split.map &:to_i
a=(1..m).map{gets.split.map(&:to_i)+[0]}+[[0]*n]
$p=(0...m*n).to_a
print (0...m).any?{|x|(0...n).any?{|y|
  [[x+1,y],[x,y+1]].any?{|z,w|
    a[x][y]==a[z][w]&&(
      u=r x*n+y
      v=r z*n+w
      $p[u]=v
      u==v
    )
  }
}}?'':'im','possible'
0