結果

問題 No.1577 織姫と彦星2
ユーザー yuruhiyayuruhiya
提出日時 2021-06-29 20:55:28
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 545 bytes
コンパイル時間 20,106 ms
コンパイル使用メモリ 257,832 KB
実行使用メモリ 12,148 KB
最終ジャッジ日時 2023-09-08 06:03:53
合計ジャッジ時間 22,909 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,520 KB
testcase_01 AC 3 ms
4,424 KB
testcase_02 AC 3 ms
4,544 KB
testcase_03 AC 2 ms
4,424 KB
testcase_04 AC 2 ms
4,520 KB
testcase_05 AC 16 ms
6,032 KB
testcase_06 AC 6 ms
5,068 KB
testcase_07 AC 49 ms
9,340 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 18 ms
6,288 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 3 ms
4,536 KB
testcase_19 AC 50 ms
8,780 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 22 ms
6,832 KB
testcase_27 AC 41 ms
8,276 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 29 ms
7,036 KB
testcase_31 WA -
testcase_32 AC 3 ms
4,640 KB
testcase_33 AC 3 ms
4,672 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 35 ms
8,004 KB
testcase_43 AC 37 ms
8,196 KB
testcase_44 AC 4 ms
4,852 KB
testcase_45 WA -
testcase_46 AC 13 ms
5,572 KB
testcase_47 AC 46 ms
8,984 KB
testcase_48 WA -
testcase_49 AC 25 ms
6,984 KB
testcase_50 AC 19 ms
6,580 KB
testcase_51 AC 6 ms
5,104 KB
testcase_52 AC 63 ms
11,516 KB
testcase_53 AC 62 ms
9,808 KB
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = read_line.to_i
s, t = read_line.split.map(&.to_i)
a = read_line.split.map(&.to_i)
stones = a + [s, t]
hash = stones.zip(0..).to_h
g = (1..n + 2).map { [] of Int32 }
stones.each_with_index do |x, i|
  (0..30).each do |bit|
    if j = hash[x ^ (1 << bit)]?
      g[i] << j; g[j] << i
    end
  end
end

que = Deque{hash[s]}
dist = [nil.as(Int32?)] * (n + 2)
dist[hash[s]] = 0
while v = que.pop?
	d = dist[v].not_nil!
	puts(d - 1) + exit if v == hash[t]
	g[v].each do |u|
		if dist[u].nil?
			dist[u] = d + 1
			que << u
		end
	end
end
puts -1
0