結果

問題 No.1588 Connection
ユーザー kona0001kona0001
提出日時 2021-07-08 23:12:06
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 643 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 11,520 KB
実行使用メモリ 33,500 KB
平均クエリ数 518.06
最終ジャッジ日時 2023-09-24 11:33:57
合計ジャッジ時間 6,338 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
31,068 KB
testcase_01 RE -
testcase_02 AC 106 ms
31,112 KB
testcase_03 AC 110 ms
31,384 KB
testcase_04 AC 111 ms
30,668 KB
testcase_05 AC 108 ms
30,972 KB
testcase_06 AC 109 ms
30,708 KB
testcase_07 AC 108 ms
31,336 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 105 ms
30,844 KB
testcase_15 AC 105 ms
31,472 KB
testcase_16 AC 104 ms
30,696 KB
testcase_17 AC 104 ms
31,200 KB
testcase_18 AC 105 ms
31,320 KB
testcase_19 AC 107 ms
31,212 KB
testcase_20 AC 111 ms
32,808 KB
testcase_21 WA -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 161 ms
33,092 KB
testcase_26 AC 161 ms
33,500 KB
testcase_27 AC 132 ms
31,288 KB
testcase_28 AC 124 ms
30,924 KB
testcase_29 RE -
testcase_30 AC 201 ms
31,048 KB
testcase_31 AC 106 ms
31,312 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:8: warning: assigned but unused variable - z
Syntax OK

ソースコード

diff #

n,m = gets.chomp.split(" ").map(&:to_i)
#0:未探索 1:探索済み
visited = Array.new(n+1){Array.new(n+1,false)}
visited[1][1] = true
queue = [[1,1]]
black = m-2
while queue.empty?.!
  x,y,z = queue[0]
  queue.shift
  next if black < n-x + n-y - 1
  [[1,0],[0,1],[-1,0],[0,-1]].each do |dx,dy|
    nx = x+dx
    ny = y+dy
    next if nx < 1 || ny < 1 || n < nx && n < ny
    next if visited[nx][ny]
    if nx == n && ny == n
      puts "Yes"
      exit
    end
    puts "#{nx} #{ny}"
    $stdout.flush
    inp = gets.chomp
    visited[nx][ny] = true
    if inp == "Black"
      queue << [nx,ny]
      black -= 1
    end
  end
end
puts "No"
0