質問編集履歴
4
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,13 +28,13 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
-
N = int(input())
|
31
|
+
N = int(input().rstrip())
|
32
32
|
|
33
33
|
|
34
34
|
|
35
35
|
def check(pre_t, t, sx, sy, gx, gy):
|
36
36
|
|
37
|
-
|
37
|
+
# 以前の状態から上下左右動かして初期設定する
|
38
38
|
|
39
39
|
candidate = [[pre_t, sx + 1, sy], [pre_t, sx - 1, sy], [pre_t, sx, sy + 1], [pre_t, sx, sy - 1]]
|
40
40
|
|
@@ -46,7 +46,9 @@
|
|
46
46
|
|
47
47
|
t2, now_x, now_y = candidate.pop(0)
|
48
48
|
|
49
|
+
|
49
50
|
|
51
|
+
# time < tのときまだちゃんと到達できるか調査中の段階なので上下左右再び追加する
|
50
52
|
|
51
53
|
if t2 < t:
|
52
54
|
|
@@ -64,11 +66,7 @@
|
|
64
66
|
|
65
67
|
return True
|
66
68
|
|
67
|
-
|
69
|
+
|
68
|
-
|
69
|
-
# continue
|
70
|
-
|
71
|
-
|
72
70
|
|
73
71
|
if len(candidate) == 0:
|
74
72
|
|
@@ -76,7 +74,7 @@
|
|
76
74
|
|
77
75
|
|
78
76
|
|
79
|
-
|
77
|
+
# 原点からスタートするための初期設定
|
80
78
|
|
81
79
|
pre_t, sx, sy = 1, 0, 0
|
82
80
|
|
@@ -84,9 +82,13 @@
|
|
84
82
|
|
85
83
|
for i in range(N):
|
86
84
|
|
87
|
-
t, gx, gy = map(int, input().split(" "))
|
85
|
+
t, gx, gy = map(int, input().rstrip().split(" "))
|
86
|
+
|
87
|
+
# もしちゃんとただりつけるのであれば
|
88
88
|
|
89
89
|
if check(pre_t, t, sx, sy, gx, gy):
|
90
|
+
|
91
|
+
# 次の準備をする
|
90
92
|
|
91
93
|
pre_t = t + 1
|
92
94
|
|
@@ -114,4 +116,6 @@
|
|
114
116
|
|
115
117
|
|
116
118
|
|
119
|
+
|
120
|
+
|
117
121
|
```
|
3
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,13 +28,13 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
-
N = int(input()
|
31
|
+
N = int(input())
|
32
32
|
|
33
33
|
|
34
34
|
|
35
35
|
def check(pre_t, t, sx, sy, gx, gy):
|
36
36
|
|
37
|
-
|
37
|
+
|
38
38
|
|
39
39
|
candidate = [[pre_t, sx + 1, sy], [pre_t, sx - 1, sy], [pre_t, sx, sy + 1], [pre_t, sx, sy - 1]]
|
40
40
|
|
@@ -44,33 +44,31 @@
|
|
44
44
|
|
45
45
|
while True:
|
46
46
|
|
47
|
-
|
47
|
+
t2, now_x, now_y = candidate.pop(0)
|
48
48
|
|
49
|
-
time, now_x, now_y = candidate.pop(0)
|
50
49
|
|
51
|
-
|
52
50
|
|
53
|
-
|
51
|
+
if t2 < t:
|
54
52
|
|
55
|
-
i
|
53
|
+
candidate.append([t2 + 1, now_x + 1, now_y])
|
56
54
|
|
57
|
-
candidate.append([t
|
55
|
+
candidate.append([t2 + 1, now_x - 1, now_y])
|
58
56
|
|
59
|
-
candidate.append([t
|
57
|
+
candidate.append([t2 + 1, now_x, now_y + 1])
|
60
58
|
|
61
|
-
candidate.append([t
|
59
|
+
candidate.append([t2 + 1, now_x, now_y - 1])
|
62
60
|
|
63
|
-
candidate.append([time + 1, now_x, now_y - 1])
|
64
|
-
|
65
|
-
elif t
|
61
|
+
elif t2 == t:
|
66
62
|
|
67
63
|
if now_x == gx and now_y == gy:
|
68
64
|
|
69
65
|
return True
|
70
66
|
|
71
|
-
|
67
|
+
# else:
|
72
68
|
|
73
|
-
#
|
69
|
+
# continue
|
70
|
+
|
71
|
+
|
74
72
|
|
75
73
|
if len(candidate) == 0:
|
76
74
|
|
@@ -78,7 +76,7 @@
|
|
78
76
|
|
79
77
|
|
80
78
|
|
81
|
-
|
79
|
+
|
82
80
|
|
83
81
|
pre_t, sx, sy = 1, 0, 0
|
84
82
|
|
@@ -86,13 +84,9 @@
|
|
86
84
|
|
87
85
|
for i in range(N):
|
88
86
|
|
89
|
-
t, gx, gy = map(int, input().
|
87
|
+
t, gx, gy = map(int, input().split(" "))
|
90
|
-
|
91
|
-
# もしちゃんとただりつけるのであれば
|
92
88
|
|
93
89
|
if check(pre_t, t, sx, sy, gx, gy):
|
94
|
-
|
95
|
-
# 次の準備をする
|
96
90
|
|
97
91
|
pre_t = t + 1
|
98
92
|
|
@@ -118,4 +112,6 @@
|
|
118
112
|
|
119
113
|
|
120
114
|
|
115
|
+
|
116
|
+
|
121
117
|
```
|
2
前提の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
AtCoder Beginners Selectionの最後の問題の、ABC086C 「Traveling」の問題を解いています。
|
1
|
+
AtCoder Beginners Selectionの最後の問題の、ABC086C 「Traveling」の問題をPythonで解いています。
|
2
2
|
|
3
3
|
|
4
4
|
|
1
コードのコメント追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -43,6 +43,8 @@
|
|
43
43
|
# TrueかFalseを返す
|
44
44
|
|
45
45
|
while True:
|
46
|
+
|
47
|
+
#現時点での座標及び時間を取得する
|
46
48
|
|
47
49
|
time, now_x, now_y = candidate.pop(0)
|
48
50
|
|