結果

問題 No.1588 Connection
ユーザー simansiman
提出日時 2021-07-20 00:05:17
言語 Ruby
(3.3.0)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 612 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 11,404 KB
実行使用メモリ 36,756 KB
平均クエリ数 431.19
最終ジャッジ日時 2023-09-24 12:43:22
合計ジャッジ時間 6,314 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
31,120 KB
testcase_01 AC 108 ms
30,904 KB
testcase_02 AC 108 ms
31,180 KB
testcase_03 AC 110 ms
31,060 KB
testcase_04 AC 108 ms
31,000 KB
testcase_05 AC 110 ms
30,944 KB
testcase_06 AC 108 ms
30,908 KB
testcase_07 AC 107 ms
30,956 KB
testcase_08 AC 109 ms
31,084 KB
testcase_09 AC 107 ms
31,256 KB
testcase_10 AC 107 ms
30,768 KB
testcase_11 AC 107 ms
31,200 KB
testcase_12 AC 118 ms
31,628 KB
testcase_13 AC 127 ms
31,524 KB
testcase_14 AC 107 ms
30,840 KB
testcase_15 AC 110 ms
30,880 KB
testcase_16 AC 109 ms
30,728 KB
testcase_17 AC 108 ms
31,096 KB
testcase_18 AC 111 ms
31,468 KB
testcase_19 AC 110 ms
31,920 KB
testcase_20 AC 117 ms
35,412 KB
testcase_21 AC 194 ms
36,756 KB
testcase_22 AC 194 ms
36,580 KB
testcase_23 AC 143 ms
32,900 KB
testcase_24 AC 130 ms
31,840 KB
testcase_25 AC 173 ms
35,668 KB
testcase_26 AC 171 ms
35,480 KB
testcase_27 AC 134 ms
32,268 KB
testcase_28 AC 127 ms
31,712 KB
testcase_29 AC 187 ms
32,216 KB
testcase_30 AC 169 ms
32,792 KB
testcase_31 AC 105 ms
30,920 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)

def query(a, b)
  STDOUT.puts("%d %d" % [a, b])
  STDOUT.flush
  gets.chomp
end

G = Array.new(N) { Array.new(N, 0) }

visited = Array.new(N) { Array.new(N, false) }

DY = [-1, 0, 1, 0]
DX = [0, 1, 0, -1]

def dfs(y, x, visited)
  visited[y][x] = true

  if y == N - 1 && x == N - 1
    puts 'Yes'
    exit
  end

  4.times do |i|
    ny = y + DY[i]
    nx = x + DX[i]

    next if ny < 0 || nx < 0 || N <= ny || N <= nx
    next if visited[ny][nx]

    res = query(ny + 1, nx + 1)

    if res == 'Black'
      dfs(ny, nx, visited)
    end
  end
end

dfs(0, 0, visited)

puts 'No'
0