質問編集履歴

2

修正したコードを追記

2019/05/19 09:38

投稿

amatsukixprog
amatsukixprog

スコア17

test CHANGED
File without changes
test CHANGED
@@ -117,3 +117,65 @@
117
117
  ・テストケースが保存されている場所は見つけましたが、今回の問題は置いていないようでした。
118
118
 
119
119
  [テストケース](https://atcoder.jp/posts/20)
120
+
121
+
122
+
123
+ ### ご指摘いただき、修正したコード
124
+
125
+ ```Ruby
126
+
127
+ $H,$W=gets.chomp.split.map(&:to_i)
128
+
129
+ $map=$H.times.map { gets.chomp.chars }
130
+
131
+ $reached=Array.new($H){Array.new($W,0)}
132
+
133
+ $a=false
134
+
135
+
136
+
137
+ def t(y,x)
138
+
139
+ return if y<0 || y>=$H
140
+
141
+ return if x<0 || x>=$W
142
+
143
+ return if $map[y][x]=='#'
144
+
145
+ return if $reached[y][x]==1
146
+
147
+ $a=true if $map[y][x]=='g'
148
+
149
+
150
+
151
+ $reached[y][x]=1
152
+
153
+
154
+
155
+ t(y-1,x)
156
+
157
+ t(y,x+1)
158
+
159
+ t(y+1,x)
160
+
161
+ t(y,x-1)
162
+
163
+ end
164
+
165
+
166
+
167
+ y,x = $map.each_with_index{|line, ix|
168
+
169
+ found = line.index('s')
170
+
171
+ break [ix,found] if found
172
+
173
+ }
174
+
175
+
176
+
177
+ t(y,x)
178
+
179
+ puts $a ? 'Yes' : 'No'
180
+
181
+ ```

1

リンクの修正

2019/05/19 09:38

投稿

amatsukixprog
amatsukixprog

スコア17

test CHANGED
File without changes
test CHANGED
@@ -2,13 +2,11 @@
2
2
 
3
3
  AtCoderのATC001-A問題です。
4
4
 
5
- https://atcoder.jp/contests/atc001/tasks/dfs_a>
5
+ [問題文](https://atcoder.jp/contests/atc001/tasks/dfs_a)
6
6
 
7
7
 
8
8
 
9
9
  上記のページを参考に、コードを作成したのですが提出した際にREとWAが発生します。
10
-
11
- https://atcoder.jp/contests/atc001/submissions/5439696
12
10
 
13
11
  REが発生した時はエラーメッセージもなく、WAが発生した時はどのような入力がされたときなのかわかりません。
14
12
 
@@ -118,4 +116,4 @@
118
116
 
119
117
  ・テストケースが保存されている場所は見つけましたが、今回の問題は置いていないようでした。
120
118
 
121
- https://atcoder.jp/posts/20
119
+ [テストケース](https://atcoder.jp/posts/20)