質問するログイン新規登録

質問編集履歴

2

修正したコードを追記

2019/05/19 09:38

投稿

amatsukixprog
amatsukixprog

スコア17

title CHANGED
File without changes
body CHANGED
@@ -57,4 +57,35 @@
57
57
  ・問題文に掲載されている入力例からは正しく出力されていました。
58
58
 
59
59
  ・テストケースが保存されている場所は見つけましたが、今回の問題は置いていないようでした。
60
- [テストケース](https://atcoder.jp/posts/20)
60
+ [テストケース](https://atcoder.jp/posts/20)
61
+
62
+ ### ご指摘いただき、修正したコード
63
+ ```Ruby
64
+ $H,$W=gets.chomp.split.map(&:to_i)
65
+ $map=$H.times.map { gets.chomp.chars }
66
+ $reached=Array.new($H){Array.new($W,0)}
67
+ $a=false
68
+
69
+ def t(y,x)
70
+ return if y<0 || y>=$H
71
+ return if x<0 || x>=$W
72
+ return if $map[y][x]=='#'
73
+ return if $reached[y][x]==1
74
+ $a=true if $map[y][x]=='g'
75
+
76
+ $reached[y][x]=1
77
+
78
+ t(y-1,x)
79
+ t(y,x+1)
80
+ t(y+1,x)
81
+ t(y,x-1)
82
+ end
83
+
84
+ y,x = $map.each_with_index{|line, ix|
85
+ found = line.index('s')
86
+ break [ix,found] if found
87
+ }
88
+
89
+ t(y,x)
90
+ puts $a ? 'Yes' : 'No'
91
+ ```

1

リンクの修正

2019/05/19 09:38

投稿

amatsukixprog
amatsukixprog

スコア17

title CHANGED
File without changes
body CHANGED
@@ -1,9 +1,8 @@
1
1
  ### 前提・実現したいこと
2
2
  AtCoderのATC001-A問題です。
3
- https://atcoder.jp/contests/atc001/tasks/dfs_a>
3
+ [問題文](https://atcoder.jp/contests/atc001/tasks/dfs_a)
4
4
 
5
5
  上記のページを参考に、コードを作成したのですが提出した際にREとWAが発生します。
6
- https://atcoder.jp/contests/atc001/submissions/5439696
7
6
  REが発生した時はエラーメッセージもなく、WAが発生した時はどのような入力がされたときなのかわかりません。
8
7
  エラーメッセージの確認方法などの、原因を特定する方法があれば教えていただきたいです。
9
8
  また、ソースコードにおかしい点があれば指摘して頂けますと幸いです。
@@ -58,4 +57,4 @@
58
57
  ・問題文に掲載されている入力例からは正しく出力されていました。
59
58
 
60
59
  ・テストケースが保存されている場所は見つけましたが、今回の問題は置いていないようでした。
61
- https://atcoder.jp/posts/20
60
+ [テストケース](https://atcoder.jp/posts/20)