output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s620961306
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
a, b, c, d = map(int, input().split()) Str = "" U_1st_num = d - b for i in range(U_1st_num): Str = Str + "U" R_1st_num = c - a for i in range(R_1st_num): Str = Str + "R" D_2nd_num = d - b for i in range(D_2nd_num): Str = Str + "D" L_2nd_num = c - a for i in range(L_2nd_num): Str = Str + "L" Str = Str + "L" for i in range(U_1st_num + 1): Str = Str + "U" for i in range(R_1st_num + 1): Str = Str + "R" Str = Str + "D" Str = Str + "R" for i in range(D_2nd_num + 1): Str = Str + "D" for i in range(L_2nd_num + 1): Str = Str + "L" Str = Str + "U" print(Str)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s031118479
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) res = "" if tx - sx < 0: res += abs(tx - sx) * "L" else: res += abs(tx - sx) * "R" if ty - sy < 0: res += abs(ty - sy) * "D" else: res += abs(ty - sy) * "U" N = len(res) tmp1 = res tmp2 = "" for i in range(N): if res[i] == "U": tmp2 += "D" if res[i] == "D": tmp2 += "U" if res[i] == "R": tmp2 += "L" if res[i] == "L": tmp2 += "R" res = tmp1 + tmp2 tmp3 = "" for i in range(N - 1): if tmp1[i] != tmp1[i + 1]: tmp3 = tmp1[:i] + tmp1[i] + tmp1[i:] tmp3 = tmp2[-1] + tmp3 + tmp3[-1] + tmp2[0] res = res + tmp3 N = len(tmp3) tmp4 = "" for i in range(N): if tmp3[i] == "U": tmp4 += "D" if tmp3[i] == "D": tmp4 += "U" if tmp3[i] == "R": tmp4 += "L" if tmp3[i] == "L": tmp4 += "R" res = res + tmp4 print(res)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s231832584
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
""" N = list(map(int,input().split())) S = [str(input()) for _ in range(N)] S = [list(map(int,list(input()))) for _ in range(h)] print(*S,sep="") """ import sys sys.setrecursionlimit(10**6) input = lambda: sys.stdin.readline().rstrip() inf = float("inf") # 無限 def reverse(temp): out = "" for x in temp: if x == "U": out += "D" elif x == "D": out += "U" elif x == "R": out += "L" else: out += "R" return out sx, sy, tx, ty = map(int, input().split()) A = "" B = "" C = "" D = "" # A if sy < ty: A += "U" * (ty - sy) else: A += "D" * (sy - ty) if sx < tx: A += "R" * (tx - sx) else: A += "L" * (sx - tx) B = reverse(A) C += B[-1] + A[0] + A + A[-1] + B[0] D = reverse(C) print(A + B + C + D)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s616464805
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) dx = tx - sx dy = ty - sy if dx >= 0: if dy >= 0: ans = ( "U" * dy + "R" * dx + "D" * dy + "L" * (dx + 1) + "U" * (dy + 1) + "R" * (dx + 1) + "D" + "R" + "D" * (dy + 1) + "L" * (dx + 1) + "U" ) else: ans = ( "D" * dy + "R" * dx + "U" * dy + "L" * (dx + 1) + "D" * (dy + 1) + "R" * (dx + 1) + "U" + "R" + "U" * (dy + 1) + "L" * (dx + 1) + "D" ) else: if dy >= 0: ans = ( "U" * dy + "L" * dx + "D" * dy + "R" * (dx + 1) + "U" * (dy + 1) + "L" * (dx + 1) + "D" + "L" + "D" * (dy + 1) + "R" * (dx + 1) + "U" ) else: ans = ( "D" * dy + "L" * dx + "U" * dy + "R" * (dx + 1) + "D" * (dy + 1) + "L" * (dx + 1) + "U" + "L" + "U" * (dy + 1) + "R" * (dx + 1) + "D" ) print(ans)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s976354102
Wrong Answer
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) move = ["R", "U", "L", "D"] text = "" x = abs(sx - tx) y = abs(sy - ty) a = tx - sx >= 0 b = ty - sy >= 0 ugoki = ( [x, 0], [y, 1], [x, 2], [y, 3], [1, 3], [x + 1, 0], [y + 1, 1], [1, 2], [1, 1], [x + 1, 2], [y + 1, 3], ) ugoki2 = ( [x, 2], [y, 1], [x, 0], [y, 3], [1, 3], [x + 1, 2], [y + 1, 1], [1, 0], [1, 1], [x + 1, 0], [y + 1, 3], ) c = [] if a and b: c = ugoki elif not a and not b: c = ugoki elif not a and b: c = ugoki2 elif a and not b: c = ugoki2 for i in range(10): for n in range(c[i][0]): if (not a and not b) or (a and not b): text += move[(c[i][1] + 2) % 4] else: text += move[c[i][1]] print(text)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s791398972
Wrong Answer
p03836
The input is given from Standard Input in the following format: sx sy tx ty
a, b, c, d = map(int, input().split()) r = str() if c - a > 0: r += "R" * (c - a) else: r += "L" * (a - c) if d - b > 0: r += "U" * (d - b) else: r += "D"(b - d) for i in range(len(r)): if r[i] == "R": r += "L" if r[i] == "L": r += "R" if r[i] == "U": r += "D" if r[i] == "D": r += "U" # 一週目おわり t = len(r) if d - b > 0: r += "D" else: r += "U" if c - a > 0: r += "R" * (c - a + 1) else: r += "L" * (a - c + 1) if d - b > 0: r += "U" * (d - b + 1) else: r += "D"(b - d + 1) if c - a > 0: r += "L" else: r += "R" for i in range(t + 1, len(r)): if r[i] == "R": r += "L" if r[i] == "L": r += "R" if r[i] == "U": r += "D" if r[i] == "D": r += "U" print(r)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s922747494
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) dx = tx - sx dy = ty - sy Dx = abs(dx) Dy = abs(dy) val = ( "U" * Dy + "R" * Dx + "D" * Dy + "L" * (Dx + 1) + "U" * (Dy + 1) + "R" * (Dx + 1) + "D" + "R" + "D" * (Dy + 1) + "L" * (Dx + 1) + "U" ) ans_l = [] for _ in range(len(val)): ans_l.append(val[_]) l = len(ans_l) if dy < 0: for i in range(l): if ans_l[i] == "U": ans_l[i] = "D" elif ans_l[i] == "D": ans_l[i] = "U" if dx < 0: for j in range(l): if ans_l[j] == "R": ans_l[j] = "L" elif ans_l[j] == "L": ans_l[j] = "R" print("".join(ans_l))
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s872213619
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) home = [sx, sy] goal = [tx, ty] point = [sx, sy] ans_li = [] def move_to(start, end): while start != end: if start[0] > end[0]: start[0] -= 1 ans_li.append("L") if start[0] < end[0]: start[0] += 1 ans_li.append("R") if start[1] > end[1]: start[1] -= 1 ans_li.append("D") if start[1] < end[1]: start[1] += 1 ans_li.append("U") move_to(home, [sx, ty]) move_to([sx, ty], [tx, ty]) move_to(goal, [tx, sy]) move_to([tx, sy], [sx, sy]) ans_li.append("L") move_to([sx - 1, sy], [sx - 1, ty + 1]) move_to([sx - 1, ty + 1], [tx, ty + 1]) ans_li.append("D") ans_li.append("R") move_to([tx + 1, ty], [tx + 1, sy - 1]) move_to([tx + 1, sy - 1], [sx, sy - 1]) ans_li.append("U") print("".join(ans_li))
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s458977518
Wrong Answer
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = list(map(int, input().split())) dx, dy = tx - sx, ty - sy sx = "R" if dx >= 0 else "L" sy = "U" if dy >= 0 else "D" first = sx * abs(dx) + sy * abs(dy) trans = str.maketrans("UDRL", "DULR") def rev(s): return s.translate(trans) print(first) if dx != 0 and dy != 0: print(rev(first), end="") d = "L" if dx > 0 else "R" d2 = "D" if dy > 0 else "U" print(d2, d, first, rev(d), rev(d2), sep="", end="") print(rev(d2 + d + first + rev(d) + rev(d2)), sep="", end="") else: d = "R" if dx is 0 else "U" second = d + rev(first) + rev(d) print(second, end="") print(rev(second), end="") d2 = first[0] print(d2, d * 2, rev(d2), rev(first), rev(d2), rev(d) * 2, rev(d2), sep="", end="")
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s844682815
Wrong Answer
p03836
The input is given from Standard Input in the following format: sx sy tx ty
#! /usr/bin/python # Back and Forth """ −1000≦sx<tx≦1000 −1000≦sy<ty≦1000 sx,sy,tx,ty は整数である。 """ test_mode = False sx, sy, tx, ty = map(int, input().split()) dx = tx - sx dy = ty - sy abs_dx = abs(dx) abs_dy = abs(dy) if test_mode: print("dx = {}".format(dx)) print("dy = {}".format(dy)) print("abs_dx = {}".format(abs_dx)) print("abs_dy = {}".format(abs_dy)) def course_type(x, y): """ x, y について 0: x,y 両方が でない 1: x だけが 0 2: y だけが 0 3: x,y 両方が 0 を返す。入力は絶対値でよろしく。 """ if x != 0 and y != 0: return 0 if x == 0 and y != 0: return 1 if x != 0 and y == 0: return 2 return 3 def course_temp(x, y): """ とりあえず (0, 0)→(x, y) の2往復のしかたを返す関数。 x,y >= 0 とすること。※第1象限で考えるため """ s = "" flag = course_type(x, y) if flag == 0: # 2点が線分上にない場合 # ここから 1往復目 for _ in range(x): s += "R" for _ in range(y): s += "U" for _ in range(x): s += "L" for _ in range(y): s += "D" # ここまで 1往復目 # ここから 2往復目 s += "U" for _ in range(x + 1): s += "R" for _ in range(y + 1): s += "U" s += "L" s += "U" for _ in range(x + 1): s += "L" for _ in range(y + 1): s += "D" s += "R" # ここまで 2往復目 elif flag == 1: # ここから 1往復目 for _ in range(y + 1): s += "U" s += "L" s += "L" for _ in range(y + 2): s += "D" s += "R" s += "R" s += "U" # ここまで 1往復目 # ここから 2往復目 s += "R" for _ in range(y): s += "U" s += "L" s += "L" for _ in range(y): s += "D" s += "R" # ここまで 2往復目 elif flag == 2: # ここから 1往復目 for _ in range(y + 1): s += "R" s += "U" s += "U" for _ in range(y + 2): s += "L" s += "D" s += "D" s += "R" # ここまで 1往復目 # ここから 2往復目 s += "D" for _ in range(y): s += "R" s += "U" s += "U" for _ in range(y): s += "L" s += "D" # ここまで 2往復目 else: pass return s def convert(s): """ dx, dy の符号に応じて 文字列s を変換して返す関数 """ if dx >= 0: pass else: s.translate( str.maketrans( "RL", "LR", ) ) # x方向の移動を反転 if dy >= 0: pass else: s.translate( str.maketrans( "UD", "DU", ) ) # y方向の移動を反転 return s def main(): """ 全体の処理を実行する関数 """ course = course_temp(abs_dx, abs_dy) if test_mode: print("course:", course) course = convert(course) if test_mode: print("course:", course) print(course) if __name__ == "__main__": main() """ 参考 Pythonで文字列を置換(replace, translate, re.sub, re.subn) https://note.nkmk.me/python-str-replace-translate-re-sub/ """
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s845960587
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, gx, gy = list(map(int, input().split())) dx, dy = gx - sx, gy - sy out = [] out.append("R" * dx) out.append("U" * dy) out.append("L" * dx) out.append("D" * dy) out.append("D") out.append("R" * (dx + 1)) out.append("U" * (dy + 1)) out.append("L") out.append("U") out.append("L" * (dx + 1)) out.append("D" * (dy + 1)) out.append("R") print("".join(out))
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s285918743
Wrong Answer
p03836
The input is given from Standard Input in the following format: sx sy tx ty
walklist = [] a, b, c, d = map(int, input().split()) x_diff = c - a y_diff = d - b walklist.append("U" * y_diff) walklist.append("R" * x_diff) walklist.append("D" * y_diff) walklist.append("L" * (x_diff + 1)) walklist.append("U" * (y_diff + 1)) walklist.append("R" * (x_diff + 2)) walklist.append("D" * (y_diff + 2)) walklist.append("L" * (x_diff + 1)) walklist.append("U") print("".join(walklist))
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s457064269
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
import sys from sys import exit from collections import deque from bisect import bisect_left, bisect_right, insort_left, insort_right from heapq import heapify, heappop, heappush from itertools import product, permutations, combinations, combinations_with_replacement from functools import reduce from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians sys.setrecursionlimit(10**6) INF = 10**20 eps = 1.0e-20 MOD = 10**9 + 7 def lcm(x, y): return x * y // gcd(x, y) def lgcd(l): return reduce(gcd, l) def llcm(l): return reduce(lcm, l) def powmod(n, i, mod): return pow(n, mod - 1 + i, mod) if i < 0 else pow(n, i, mod) def div2(x): return x.bit_length() def div10(x): return len(str(x)) - (x == 0) def perm(n, mod=None): ans = 1 for i in range(1, n + 1): ans *= i if mod != None: ans %= mod return ans def intput(): return int(input()) def mint(): return map(int, input().split()) def lint(): return list(map(int, input().split())) def ilint(): return int(input()), list(map(int, input().split())) def judge(x, l=["Yes", "No"]): print(l[0] if x else l[1]) def lprint(l, sep="\n"): for x in l: print(x, end=sep) def ston(c, c0="a"): return ord(c) - ord(c0) def ntos(x, c0="a"): return chr(x + ord(c0)) class counter(dict): def __init__(self, *args): super().__init__(args) def add(self, x, d=1): self.setdefault(x, 0) self[x] += d def list(self): l = [] for k in self: l.extend([k] * self[k]) return l class comb: def __init__(self, n, mod=None): self.l = [1] self.n = n self.mod = mod def get(self, k): l, n, mod = self.l, self.n, self.mod k = n - k if k > n // 2 else k while len(l) <= k: i = len(l) l.append( l[i - 1] * (n + 1 - i) // i if mod == None else (l[i - 1] * (n + 1 - i) * powmod(i, -1, mod)) % mod ) return l[k] def pf(x): C = counter() p = 2 while x > 1: k = 0 while x % p == 0: x //= p k += 1 if k > 0: C.add(p, k) p = p + 2 - (p == 2) if p * p < x else x return C sx, sy, tx, ty = mint() ans = [] dx, dy = tx - sx, ty - sy R, L, U, D = "R", "L", "U", "D" ans.extend([R] * dx) ans.extend([U] * dy) ans.extend([L] * dx) ans.extend([D] * (dy + 1)) ans.extend([R] * (dx + 1)) ans.extend([U] * (dy + 1)) ans.extend([L, U]) ans.extend([L] * (dx + 1)) ans.extend([D] * (dy + 1)) ans.extend([R]) lprint(ans, "")
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s877243773
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
import sys input = sys.stdin.readline sx, sy, tx, ty = list(map(int, input().split())) right = tx - sx up = ty - sy go1 = "R" * right + "U" * up back1 = "" for i in range(len(go1)): if go1[i] == "R": back1 += "L" elif go1[i] == "U": back1 += "D" elif go1[i] == "L": back1 += "R" elif go1[i] == "D": back1 += "U" go2 = "D" + "R" * (right + 1) + "U" * (up + 1) + "L" back2 = "" for i in range(len(go2)): if go2[i] == "R": back2 += "L" elif go2[i] == "U": back2 += "D" elif go2[i] == "L": back2 += "R" elif go2[i] == "D": back2 += "U" print(go1 + back1 + go2 + back2)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s148247275
Wrong Answer
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split(" ")) output_txt = "" # 1st txt x1 = tx - sx if x1 > 0: txt_x1 = "R" * x1 else: txt_x1 = "L" * x1 y1 = ty - sy if y1 > 0: txt_y1 = "U" * y1 else: txt_y1 = "D" * y1 # 2nd txt if x1 > 0: txt_x2 = "L" * x1 else: txt_x2 = "R" * x1 if y1 > 0: txt_y2 = "D" * y1 else: txt_y2 = "U" * y1 # 3rd txt if y1 > 0: txt_3 = "D" else: txt_3 = "U" if x1 > 0: txt_3 += "R" * x1 + "R" else: txt_3 += "L" * x1 + "L" if y1 > 0: txt_3 = "U" * y1 + "U" else: txt_3 = "D" * y1 + "D" if x1 > 0: txt_3 += "L" else: txt_3 += "R" # 4th txt if y1 > 0: txt_4 = "U" else: txt_4 = "D" if x1 > 0: txt_4 += "L" * x1 + "L" else: txt_4 += "R" * x1 + "R" if y1 > 0: txt_4 = "D" * y1 + "D" else: txt_4 = "U" * y1 + "U" if x1 > 0: txt_4 += "R" else: txt_4 += "L" output_txt = txt_x1 + txt_y1 + txt_x2 + txt_y2 print(output_txt + txt_3 + txt_4)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s921912158
Wrong Answer
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) short_outward = [] short_return = [] long_outward = ["L"] long_return = ["R"] for i in range((ty - sy)): short_outward.append("U") for i in range((tx - sx)): short_outward.append("R") print(short_outward) for i in range((ty - sy)): short_return.append("D") for i in range((tx - sx)): short_return.append("L") print(short_return) for i in range((ty - sy) + 1): long_outward.append("U") for i in range((tx - sx) + 1): long_outward.append("R") long_outward.append("D") print(long_outward) for i in range((ty - sy) + 1): long_return.append("D") for i in range((tx - sx) + 1): long_return.append("L") long_return.append("U") print(long_return) list = short_outward + short_return + long_outward + long_return # print(list) for i in range(len(list)): print(list[i], end="")
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s611468801
Runtime Error
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) ans = "" ans += "U" * (ty - sy) + "R" * (tx - sx) ans += "D" * (ty - sy) + "L" * (tx - sx) ans += "L" + "U" * (ty - sy + 1) + "R" * (tx - sx + 1) + "D" ans += "R" + "D" * (ty - sy + 1) + "L" * (tx - sx + 1) + "U" print(ans)sx, sy, tx, ty = map(int, input().split()) ans = "" ans += "U" * (ty - sy) + "R" * (tx - sx) ans += "D" * (ty - sy) + "L" * (tx - sx) ans += "L" + "U" * (ty - sy + 1) + "R" * (tx - sx + 1) + "D" ans += "R" + "D" * (ty - sy + 1) + "L" * (tx - sx + 1) + "U" print(ans)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s780205322
Wrong Answer
p03836
The input is given from Standard Input in the following format: sx sy tx ty
SX, SY, TX, TY = map(int, input().split()) way1 = "U" * (TX - SX) + "R" * (TY - SY) way2 = "D" * (TX - SX) + "L" * (TY - SY) way3 = "L" + "U" * (TX - SX + 1) + "R" * (TY - SY + 1) + "D" way4 = "R" + "D" * (TX - SX + 1) + "L" * (TY - SY + 1) + "U" print(way1 + way2 + way3 + way4)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s486945949
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, ex, ey = [int(v) for v in input().split()] def move(x): print(x, end="") def forward(x1, y1, x2, y2): for _ in range(y1, y2): move("U") for _ in range(x1, x2): move("R") def backword(x1, y1, x2, y2): for _ in range(y1, y2): move("D") for _ in range(x1, x2): move("L") forward(sx, sy, ex, ey) backword(sx, sy, ex, ey) move("L") forward(sx - 1, sy, ex, ey + 1) move("D") move("R") backword(sx, sy - 1, ex + 1, ey) print("U")
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s419347835
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
H = list(map(int, input().split())) SX = H[0] SY = H[1] TX = H[2] TY = H[3] TX = TX - SX TY = TY - SY if (TX >= 0) & (TY >= 0): U = "U" R = "R" D = "D" L = "L" if (TX < 0) & (TY >= 0): U = "U" R = "L" D = "D" L = "R" if (TX >= 0) & (TY < 0): U = "D" R = "R" D = "U" L = "L" if (TX < 0) & (TY < 0): U = "D" R = "L" D = "U" L = "R" for i in range(abs(TY)): print(U, end="") for i in range(abs(TX)): print(R, end="") for i in range(abs(TY)): print(D, end="") for i in range(abs(TX)): print(L, end="") print(L, end="") for i in range(abs(TY) + 1): print(U, end="") for i in range(abs(TX) + 1): print(R, end="") print(D, end="") print(R, end="") for i in range(abs(TY) + 1): print(D, end="") for i in range(abs(TX) + 1): print(L, end="") print(U, end="")
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s332512076
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
import sys import math import collections import itertools import array import inspect # Set max recursion limit sys.setrecursionlimit(1000000) # Debug output def chkprint(*args): names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()} print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args)) # Binary converter def to_bin(x): return bin(x)[2:] def li_input(): return [int(_) for _ in input().split()] def gcd(n, m): if n % m == 0: return m else: return gcd(m, n % m) def gcd_list(L): v = L[0] for i in range(1, len(L)): v = gcd(v, L[i]) return v def lcm(n, m): return (n * m) // gcd(n, m) def lcm_list(L): v = L[0] for i in range(1, len(L)): v = lcm(v, L[i]) return v # Width First Search (+ Distance) def wfs_d(D, N, K): """ D: 隣接行列(距離付き) N: ノード数 K: 始点ノード """ dfk = [-1] * (N + 1) dfk[K] = 0 cps = [(K, 0)] r = [False] * (N + 1) r[K] = True while len(cps) != 0: n_cps = [] for cp, cd in cps: for i, dfcp in enumerate(D[cp]): if dfcp != -1 and not r[i]: dfk[i] = cd + dfcp n_cps.append((i, cd + dfcp)) r[i] = True cps = n_cps[:] return dfk # Depth First Search (+Distance) def dfs_d(v, pre, dist): """ v: 現在のノード pre: 1つ前のノード dist: 現在の距離 以下は別途用意する D: 隣接リスト(行列ではない) D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト """ global D global D_dfs_d D_dfs_d[v] = dist for next_v, d in D[v]: if next_v != pre: dfs_d(next_v, v, dist + d) return def sigma(N): ans = 0 for i in range(1, N + 1): ans += i return ans def comb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2, r + 1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p - 1, r, p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) return result def bisearch(L, target): low = 0 high = len(L) - 1 while low <= high: mid = (low + high) // 2 guess = L[mid] if guess == target: return True elif guess < target: low = mid + 1 elif guess > target: high = mid - 1 if guess != target: return False # -------------------------------------------- dp = None def main(): sx, sy, tx, ty = li_input() ans = "" ans += "U" * (ty - sy) ans += "R" * (tx - sx) ans += "D" * (ty - sy) ans += "L" * (tx - sx) ans += "L" ans += "U" * ((ty - sy) + 1) ans += "R" * ((tx - sx) + 1) ans += "D" ans += "R" ans += "D" * ((ty - sy) + 1) ans += "L" * ((tx - sx) + 1) ans += "U" print(ans) main()
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s841843160
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) ruto = [] for i in range(0, tx - sx): ruto.append("R") for i in range(0, ty - sy): ruto.append("U") for i in range(0, tx - sx): ruto.append("L") for i in range(0, ty - sy): ruto.append("D") ruto.append("D") for i in range(0, tx - sx + 1): ruto.append("R") for i in range(0, ty - sy + 1): ruto.append("U") ruto.append("L") ruto.append("U") for i in range(0, tx - sx + 1): ruto.append("L") for i in range(0, ty - sy + 1): ruto.append("D") ruto.append("R") for i in range(0, len(ruto)): print(ruto[i], end="")
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s494434498
Runtime Error
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) s = "" dx, dy = abs(tx - sx), abs(ty - sy) dxy = dx + dy for a in range(dx): s += "R" for b in range(dy): s += "U" for c in range(dx): s += "L" for d in range(dy): s += "D" s + = "D" for e in range(dx + 1): s += "R" for f in range(dy + 1): s + = "U" s += "U" for g in range(dx + 1): s += "L" for h in range(dy + 1): s += "D" s += "R" print(s)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s646844266
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) distance_x = tx - sx distance_y = ty - sy # 時計回りで移動することとする route_str = "" # 1回目の (sx, sy) -> (tx, ty) -> (sx, sy) は、最短経路で移動する route_str += "U" * distance_y route_str += "R" * distance_x route_str += "D" * distance_y route_str += "L" * distance_x # 2回目は、行きは左上、帰りは右下にそれぞれ1ずつ膨れて移動する route_str += "L" route_str += "U" * (distance_y + 1) route_str += "R" * (distance_x + 1) route_str += "D" route_str += "R" route_str += "D" * (distance_y + 1) route_str += "L" * (distance_x + 1) route_str += "U" print(route_str)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s054984798
Runtime Error
p03836
The input is given from Standard Input in the following format: sx sy tx ty
ef route(sx, sy, tx, ty): dx = tx - sx dy = ty - sy dx2 = dx if dx >= 0 else -dx dy2 = dy if dy >= 0 else -dy buf = "" for i in range(dx2): if dx >= 0: buf += "L" else: buf += "R" for i in range(dy2): if dy >= 0: buf += "U" else: buf += "D" return buf if __name__ == "__main__": sx, sy, tx, ty = [int(i) for i in input().split()] r1 = route(sx, sy, tx, ty) + route(tx, ty, sx, sy) r2 = "L" + route(sx-1, sy, tx, ty+1)\ + "DR" + route(tx+1, ty, sx, sy-1) + "U" print(r1 + r2)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s237520840
Runtime Error
p03836
The input is given from Standard Input in the following format: sx sy tx ty
[sx, sy, tx, ty]=list(map(int,input().split())) a1=["R"]*(tx-sx)+["U"]*(ty-sy)+["L"]*(tx-sx)+["D"]*(ty-sy) a2=["D"]+["R"]*(tx-sx+1)+["U"]*(ty-sy+1)+["L"]+["U"]+["L"]*(tx-sx+1)+["D"]*(ty-sy+1)+["R"] ans=a1+a2 for i in range(len(ans)) print(ans[i],end=" ")
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s454331580
Runtime Error
p03836
The input is given from Standard Input in the following format: sx sy tx ty
import sys 2. 3.stdin = sys.stdin 4.na = lambda: list(map(int, stdin.readline().split())) 5. 6.k,s = na() 7.ans = 0 8.for x in range(k+1): 9. for y in range(k+1): 10. z = s - (x+y) 11. if z >= 0 and z <= k: 12. ans += 1 13.print(ans)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s322346204
Wrong Answer
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) momo = "" xz = abs(tx - sx) yz = abs(ty - sy) momo += "U" * yz + "R" * xz + "D" * yz + "L" * xz momo += "L" * 1 + "U" * (yz + 1) + "R" * (xz + 1) + "D" * 1 momo += "R" * 1 + "D" * yz + "L" * 1 + "D" * 1 + "L" * xz print(momo)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s771788955
Runtime Error
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx,sy,tx,ty = map(int,input().split()) print("U"*(ty-sy)+"R"*(tx-sx)+"D"*(ty-sy)+"L"*(ty-sy)+"L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"+"R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U"
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s637595784
Runtime Error
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx,sy,tx,ty=map(int,input().split()) x=tx-sx y=ty-sy print("U"*y+"R"*x+"D"*y+"L"*(x+1)+"U"*(y+1)+"R"*(x+1)+"DR"+"D"*(y+1)+"L"*(x+1)+"U"
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s524966937
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) route1, route2, route3, route4 = "", "", "L", "R" dis_x = tx - sx dis_y = ty - sy route1 = "U" * dis_y + "R" * dis_x route2 = "D" * dis_y + "L" * dis_x route3 += "U" * (dis_y + 1) + "R" * (dis_x + 1) + "D" route4 += "D" * (dis_y + 1) + "L" * (dis_x + 1) + "U" print(route1 + route2 + route3 + route4)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s672381267
Wrong Answer
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) # 直角にいく&回り込むで2往復 dx, dy = tx - sx, ty - sy one = "R" * dx + "U" * dy # print(one) two = one[::-1].replace("R", "L").replace("U", "D") # print(two) three = "D" + "R" * (dx + 1) + "U" * (dy + 1) + "L" # print(three) four = three[::-1] four = four.replace("D", "d").replace("R", "r").replace("U", "u").replace("L", "l") four = four.replace("d", "U").replace("r", "L").replace("u", "D").replace("l", "R") # print(four) print(one + two + three + four)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s959671204
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split(" ")) fir1, sec = "", "" txt = "" if ty - sy > 0 and tx - sx > 0: fir1 = "U" * (ty - sy) + "R" * (tx - sx) fir2 = "D" * (ty - sy) + "L" * (tx - sx) sec = "LU" + fir1 + "RDRD" + fir2 + "LU" elif ty - sy > 0 and tx - sx < 0: fir1 = "U" * (ty - sy) + "L" * (sx - tx) fir2 = "D" * (ty - sy) + "R" * (sx - tx) sec = "RU" + fir1 + "LDLD" + fir2 + "RU" elif ty - sy < 0 and tx - sx > 0: fir1 = "D" * (sy - ty) + "R" * (tx - sx) fir2 = "U" * (sy - ty) + "L" * (tx - sx) sec = "LD" + fir1 + "RURU" + fir2 + "LD" else: fir1 = "D" * (sy - ty) + "L" * (sx - tx) fir2 = "U" * (sy - ty) + "R" * (sx - tx) sec = "RD" + fir1 + "LULU" + fir2 + "RD" print(fir1 + fir2 + sec)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s044810334
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
def sign(x): if x > 0: return 1 if x == 0: return 0 return -1 def solve(): move_x = ["", "R", "L"] move_y = ["", "U", "D"] sx, sy, tx, ty = list(map(int, input().split())) dx = tx - sx dy = ty - sy outward = "" homeward = "" outward = move_x[sign(dx)] * abs(dx) + move_y[sign(dy)] * abs(dy) homeward = move_x[-sign(dx)] * abs(dx) + move_y[-sign(dy)] * abs(dy) fir_route = outward + homeward sec_route = ( move_y[-sign(dy)] + move_x[sign(dx)] + outward + move_y[sign(dy)] + move_x[-sign(dx)] + move_y[sign(dy)] + move_x[-sign(dx)] + homeward + move_y[-sign(dy)] + move_x[sign(dx)] ) print(fir_route, end="") print(sec_route) if __name__ == "__main__": solve()
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s847406972
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) directions = ["U", "D", "L", "R"] print(directions[0] * (ty - sy), end="") print(directions[3] * (tx - sx), end="") print(directions[1] * (ty - sy), end="") print(directions[2] * (tx - sx), end="") print(directions[2], end="") print(directions[0] * (ty - sy + 1), end="") print(directions[3] * (tx - sx + 1), end="") print(directions[1], end="") print(directions[3], end="") print(directions[1] * (ty - sy + 1), end="") print(directions[2] * (tx - sx + 1), end="") print(directions[0])
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s180627943
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
a, b, c, d = map(int, input().split()) # sを(0,0)にする # s = (a + (0 - a), b + (0 - b)) # g = (c + (0 - a), d + (0 - b)) s = (a, b) g = (c, d) route = [] # turn1 ->g route.append("R" * (g[0] - s[0])) route.append("U" * (g[1] - s[1])) # turn1 ->s route.append("L" * (g[0] - s[0])) route.append("D" * (g[1] - s[1])) # turn2 ->g route.append("D") route.append("R" * (g[0] - s[0] + 1)) route.append("U" * (g[1] - s[1] + 1)) route.append("L") # turn2 ->s route.append("U") route.append("L" * (g[0] - s[0] + 1)) route.append("D" * (g[1] - s[1] + 1)) route.append("R") route = "".join(route) print(route)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s005331691
Wrong Answer
p03836
The input is given from Standard Input in the following format: sx sy tx ty
x, y, tx, ty = map(int, input().split()) x_diff = tx - x y_diff = ty - y first_x_diff = "R" * abs(x_diff) if x_diff > 0 else "L" * abs(x_diff) first_y_diff = "U" * abs(y_diff) if y_diff > 0 else "D" * abs(y_diff) first_diff = first_x_diff + first_y_diff tmp_diff = first_diff.replace("R", "L") tmp_diff = tmp_diff.replace("U", "D") first_diff = first_diff + tmp_diff second_x_diff = "R" * abs(x_diff + 1) if x_diff > 0 else "L" * abs(x_diff + 1) second_y_diff = "U" * abs(y_diff + 1) if y_diff > 0 else "D" * abs(y_diff + 1) second_diff = second_x_diff + second_y_diff tmp_diff = second_diff.replace("R", "L") tmp_diff = tmp_diff.replace("U", "D") second_diff = second_diff + tmp_diff + "LDRU" res = first_diff + second_diff print(res)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s018334064
Runtime Error
p03836
The input is given from Standard Input in the following format: sx sy tx ty
X=list(map(int,input().split())) #X軸に並行 if X[2]-X[0]==0: if X[3]-X[1]>0: q=X[3]-X[1] U="U" D="D" else: q=X[1]-X[3] U="U" D="D" print(U*(q+1)+R*2+D*(q+2)+L*2+U+L+U*q+R*2+D*q+L) #Y軸に並行 if X[3]-X[1]==0: if X[2]-X[0]>0: p=X[2]-X[0] R="R" L="L" else: p=X[0]-X[2] R="L" L="R" print(R*(p+1)+U*2+L*(p+2)+D*2+R+D+R*p+U*2+L*p+D) if X[2]-X[0]!=0 and X[3]-X[1]!=0 if X[2]-X[0]>0: p=X[2]-X[0] R="R" L="L" else: p=X[0]-X[2] R="L" L="R" if X[3]-X[1]>0: q=X[3]-X[1] U="U" D="D" else: q=X[1]-X[3] U="D" D="U" print(U*p+R*(q+1)+D*(p+1)+L*(q+1)+U+L+U*(p+1)+R*(q+1)+D*(p+1)+L*q)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s776714102
Runtime Error
p03836
The input is given from Standard Input in the following format: sx sy tx ty
X=list(map(int.input().split())) ans="" if X[2]-X[0]>0: p=X[2]-X[0] U="U" D="D" else: p=X[0]-X[2] U="D" D="U" if X[3]-X[1]>0: q=X[3]-X[1] R="R" L="L" else: q=X[1]-X[3] R="L" L="R" print(U*p+R*(q+1)+D*(p+1)+L*(q+1)+U+L+U*(p+1)+R*(q+1)+D*(p+1)+L*q
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s935209242
Wrong Answer
p03836
The input is given from Standard Input in the following format: sx sy tx ty
X = list(map(int, input().split())) sx = X[0] sy = X[1] tx = X[2] ty = X[3] x = tx - sx y = ty - sy print(x, y) l1 = "U" * y + "R" * x l2 = "D" * y + "L" * x l3 = "L" + "U" * (y + 1) + "R" * (x + 1) + "D" l4 = "R" + "D" * (y + 1) + "L" * (x + 1) + "U" print(l1 + l2 + l3 + l4)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s592597501
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = map(int, input().split()) way = [] way += ["U" for _ in range(ty - sy)] way += ["R" for _ in range(tx - sx)] way += ["D" for _ in range(ty - sy)] way += ["L" for _ in range(tx - sx + 1)] way += ["U" for _ in range(ty - sy + 1)] way += ["R" for _ in range(tx - sx + 1)] way += ["D", "R"] way += ["D" for _ in range(ty - sy + 1)] way += ["L" for _ in range(tx - sx + 1)] way += ["U"] print("".join(way))
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s152699189
Accepted
p03836
The input is given from Standard Input in the following format: sx sy tx ty
sx, sy, tx, ty = [int(_) for _ in input().split()] # スタート地点を{0,0}にする tx = tx - sx ty = ty - sy if tx != 0 and ty != 0: aV = ["U", "R", "D", "L"] d1 = ty d2 = tx if ty < 0 and 0 < tx: aV = ["R", "D", "L", "U"] d1 = tx d2 = -ty if ty < 0 and tx < 0: aV = ["D", "L", "U", "R"] d1 = -ty d2 = -tx if 0 < ty and tx < 0: aV = ["L", "U", "R", "D"] d1 = -tx d2 = ty print( aV[0] * d1 + aV[1] * d2 + aV[2] * d1 + aV[3] * (d2 + 1) + aV[0] * (d1 + 1) + aV[1] * (d2 + 1) + aV[2] + aV[1] + aV[2] * (d1 + 1) + aV[3] * (d2 + 1) + aV[0] ) else: if 0 < ty and tx == 0: aV = ["U", "R", "D", "L"] d1 = ty d2 = tx if ty == 0 and 0 < tx: aV = ["R", "D", "L", "D"] d1 = tx d2 = ty if ty < 0 and tx == 0: aV = ["D", "L", "D", "R"] d1 = ty d2 = tx if ty == 0 and tx < 0: aV = ["L", "D", "R", "D"] d1 = tx d2 = ty print( aV[0] * d1 + aV[1] + aV[2] * d1 + aV[3] * 2 + aV[0] * d1 + aV[1] + aV[0] + aV[1] * 2 + aV[2] * (d1 + 2) + aV[3] * 2 + aV[0] )
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print a string S that represents a shortest path for Dolphin. The i-th character in S should correspond to his i-th movement. The directions of the movements should be indicated by the following characters: * `U`: Up * `D`: Down * `L`: Left * `R`: Right If there exist multiple shortest paths under the condition, print any of them. * * *
s561202542
Wrong Answer
p03836
The input is given from Standard Input in the following format: sx sy tx ty
X, Y, sX, sY = list(map(int, input().split())) ans = "" if sX - X >= 0: if sY - Y >= 0: ans += "R" * abs(X - sX) ans += "U" * abs(Y - sY) ans += "D" * abs(Y - sY) ans += "L" * abs(X - sX) ans += "R" * (abs(X - sX) + 2) ans += "U" * (abs(Y - sY) + 2) ans += "D" * (abs(Y - sY) + 2) ans += "L" * (abs(X - sX) + 2) else: ans += "R" * (abs(X - sX)) ans += "D" * (abs(Y - sY)) ans += "U" * (abs(Y - sY)) ans += "L" * (abs(X - sX)) ans += "R" * (abs(X - sX) + 2) ans += "D" * (abs(Y - sY) + 2) ans += "U" * (abs(Y - sY) + 2) ans += "L" * (abs(X - sX) + 2) else: if sY - Y >= 0: ans += "L" * abs(X - sX) ans += "U" * abs(Y - sY) ans += "D" * abs(Y - sY) ans += "R" * abs(X - sX) ans += "L" * (abs(X - sX) + 2) ans += "U" * (abs(Y - sY) + 2) ans += "D" * (abs(Y - sY) + 2) ans += "R" * (abs(X - sX) + 2) else: ans += "L" * abs(X - sX) ans += "U" * abs(Y - sY) ans += "D" * abs(Y - sY) ans += "R" * abs(X - sX) ans += "L" * (abs(X - sX) + 2) ans += "U" * (abs(Y - sY) + 2) ans += "D" * (abs(Y - sY) + 2) ans += "R" * (abs(X - sX) + 2) print(ans)
Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
[{"input": "0 0 1 2", "output": "UURDDLLUUURRDRDDDLLU\n \n\nOne possible shortest path is:\n\n * Going from (sx,sy) to (tx,ty) for the first time: (0,0) \u2192 (0,1) \u2192 (0,2) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the first time: (1,2) \u2192 (1,1) \u2192 (1,0) \u2192 (0,0)\n * Going from (sx,sy) to (tx,ty) for the second time: (0,0) \u2192 (-1,0) \u2192 (-1,1) \u2192 (-1,2) \u2192 (-1,3) \u2192 (0,3) \u2192 (1,3) \u2192 (1,2)\n * Going from (tx,ty) to (sx,sy) for the second time: (1,2) \u2192 (2,2) \u2192 (2,1) \u2192 (2,0) \u2192 (2,-1) \u2192 (1,-1) \u2192 (0,-1) \u2192 (0,0)\n\n* * *"}, {"input": "-2 -2 1 1", "output": "UURRURRDDDLLDLLULUUURRURRDDDLLDL"}]
Print the maximum total reward that you can earn no later than M days from today. * * *
s456356045
Runtime Error
p02948
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
n, d = list(map(int, input().split(" "))) ws = [] for _ in range(n): l, r = list(map(int, input().split(" "))) if l <= d: ws.append((l, r)) wn = len(ws) got = 0 chosen = [] for i in range(d): j = d - i candi_k = 0 candi_r = 0 candi_t = 0 for k, (t, r) in enumerate(wn): if t <= j and candi_t <= t and candi_r <= r and not k in chosen: candi_k = k candi_r = r candi_t = t chosen.append(candi_k) got += candi_r print(got)
Statement There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it. You can take and complete at most one of these jobs in a day. However, you cannot retake a job that you have already done. Find the maximum total reward that you can earn no later than M days from today. You can already start working today.
[{"input": "3 4\n 4 3\n 4 1\n 2 2", "output": "5\n \n\nYou can earn the total reward of 5 by taking the jobs as follows:\n\n * Take and complete the first job today. You will earn the reward of 3 after four days from today.\n * Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.\n\n* * *"}, {"input": "5 3\n 1 2\n 1 3\n 1 4\n 2 1\n 2 3", "output": "10\n \n\n* * *"}, {"input": "1 1\n 2 1", "output": "0"}]
Print the maximum total reward that you can earn no later than M days from today. * * *
s801062830
Runtime Error
p02948
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
class Work: count = 0 def __init__(self, payday, money): Work.count += 1 self.count = count self.payday = payday self.money = money # moneyが大きい方、同じなら早くもらえる方、それも同じなら最初に書いてある方が強い方 def __gt__(self, other): if self.money > other.money: return True if self.money == other.money: if self.payday < other.payday: return True if self.payday == other.payday: if self.count < other.count: return True return False def __ft__(self, other): if self.money < other.money: return True if self.money == other.money: if self.payday > other.payday: return True if self.payday == other.payday: if self.count > other.count: return True return False # def __eq__(self,other): # if self.money==other.money and self.payday==other.payday: # return True # return False # def __fe__(self,other): # return self.__ft__(other) or self.__eq__(other) # def __ge__(self,other): # return self.__gt__(other) or self.__eq__(other) # バイトの数、いつまでに稼ぐのか n, limit = [int(i) for i in input().split()] # バイトのリストを作り、クラスを入れる O(n) baitolist = [] for i in range(n): payday, money = [int(i) for i in input().split()] work = Work(payday, money) baitolist.append(work) # 日数でランク付け O(n) summoney = 0 rank = [[] for i in range(limit + 1)] for baito in baitolist: if baito.payday <= limit: rank[baito.payday].append(baito) accessible = [] count = 1 while baitolist and count <= limit: # 最悪O(limit) for baito in rank[count]: accessible.append(baito) accessible.sort() if accessible != []: dowork = accessible.pop() summoney += dowork.money count += 1 print(summoney)
Statement There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it. You can take and complete at most one of these jobs in a day. However, you cannot retake a job that you have already done. Find the maximum total reward that you can earn no later than M days from today. You can already start working today.
[{"input": "3 4\n 4 3\n 4 1\n 2 2", "output": "5\n \n\nYou can earn the total reward of 5 by taking the jobs as follows:\n\n * Take and complete the first job today. You will earn the reward of 3 after four days from today.\n * Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.\n\n* * *"}, {"input": "5 3\n 1 2\n 1 3\n 1 4\n 2 1\n 2 3", "output": "10\n \n\n* * *"}, {"input": "1 1\n 2 1", "output": "0"}]
Print the maximum total reward that you can earn no later than M days from today. * * *
s321799252
Accepted
p02948
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 class SegTreeIndex: """ 以下のクエリを処理する 1.update: i番目の値をxに更新する 2.get_val: 区間[l, r)の値とindex(同値があった場合は一番左)を得る """ def __init__(self, n, func, init): """ :param n: 要素数(0-indexed) :param func: 値の操作に使う関数(min, max) :param init: 要素の初期値(単位元) """ self.n = n self.func = func self.init = init # nより大きい2の冪数 n2 = 1 while n2 < n: n2 <<= 1 self.n2 = n2 self.tree = [self.init] * (n2 << 1) self.index = [self.init] * (n2 << 1) # 1段目(最下段)の初期化 for i in range(n2): self.index[i + n2] = i # 2段目以降の初期化 for i in range(n2 - 1, -1, -1): # 全部左の子の値に更新 self.index[i] = self.index[i * 2] def update(self, i, x): """ i番目の値をxに更新 :param i: index(0-indexed) :param x: update value """ i += self.n2 self.tree[i] = x while i > 1: left, right = min(i, i ^ 1), max(i, i ^ 1) if self.func(self.tree[left], self.tree[right]) == self.tree[left]: self.tree[i >> 1] = self.tree[left] self.index[i >> 1] = self.index[left] else: self.tree[i >> 1] = self.tree[right] self.index[i >> 1] = self.index[right] i >>= 1 def get_val(self, a, b): """ [a, b)の値を得る :param a: index(0-indexed) :param b: index(0-indexed) """ return self._get_val(a, b, 1, 0, self.n2) def _get_val(self, a, b, k, l, r): """ [a, b)の値を得る内部関数 :param k: 現在調べている区間のtree内index :param l, r: kが表す区間の左右端index [l, r) :return: kが表す区間と[a, b)の共通区間内での最小値。共通区間を持たない場合は初期値 """ # 範囲外なら初期値 if r <= a or b <= l: return (self.init, -1) # [a,b)が完全に[l,r)を包含するならtree[k]の値を採用 if a <= l and r <= b: return (self.tree[k], self.index[k]) # 一部だけ範囲内なら2つに分けて再帰的に調査 m = (l + r) // 2 left = self._get_val(a, b, k << 1, l, m) right = self._get_val(a, b, (k << 1) + 1, m, r) if self.func(left[0], right[0]) == left[0]: return left else: return right N, M = MAP() days = [[] for i in range(10**5 + 1)] for i in range(N): a, b = MAP() days[a].append(b) sti = SegTreeIndex(10**5 + 1, max, -INF) for i in range(10**5 + 1): days[i].sort() if len(days[i]): sti.update(i, days[i][-1]) ans = 0 for i in range(M - 1, -1, -1): val, idx = sti.get_val(0, M - i + 1) if val == -INF: continue ans += val days[idx].pop(-1) if len(days[idx]): sti.update(idx, days[idx][-1]) else: sti.update(idx, -INF) print(ans)
Statement There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it. You can take and complete at most one of these jobs in a day. However, you cannot retake a job that you have already done. Find the maximum total reward that you can earn no later than M days from today. You can already start working today.
[{"input": "3 4\n 4 3\n 4 1\n 2 2", "output": "5\n \n\nYou can earn the total reward of 5 by taking the jobs as follows:\n\n * Take and complete the first job today. You will earn the reward of 3 after four days from today.\n * Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.\n\n* * *"}, {"input": "5 3\n 1 2\n 1 3\n 1 4\n 2 1\n 2 3", "output": "10\n \n\n* * *"}, {"input": "1 1\n 2 1", "output": "0"}]
Print the maximum total reward that you can earn no later than M days from today. * * *
s908880055
Accepted
p02948
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
N, M = map(int, input().split()) A, B = zip(*(map(int, input().split()) for _ in range(N))) if N else ((), ()) class SegmentTree: def __init__(self, n, f, e): self.n = 2 ** ((n - 1).bit_length()) self.f = f self.e = e self.d = [e for _ in range(2 * self.n)] def __setitem__(self, key, value): key += self.n - 1 self.d[key] = value while key > 1: key //= 2 self.d[key] = self.f(self.d[2 * key], self.d[2 * key + 1]) def __getitem__(self, key): return self.q(key, 1, 1, self.n + 1) def q(self, key, i, left, right): return ( self.e if left >= key.stop or right <= key.start else ( self.d[i] if key.start <= left <= right <= key.stop else self.f( self.q(key, 2 * i, left, (left + right) // 2), self.q(key, 2 * i + 1, (left + right) // 2, right), ) ) ) T = SegmentTree(M, max, -1) for i in range(M + 1): T[i] = i ans = 0 for a, b in sorted(zip(A, B), key=lambda t: (-t[1], t[0])): x = T[1 : (M - a + 2)] if x != -1: ans += b T[x] = -1 print(ans)
Statement There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it. You can take and complete at most one of these jobs in a day. However, you cannot retake a job that you have already done. Find the maximum total reward that you can earn no later than M days from today. You can already start working today.
[{"input": "3 4\n 4 3\n 4 1\n 2 2", "output": "5\n \n\nYou can earn the total reward of 5 by taking the jobs as follows:\n\n * Take and complete the first job today. You will earn the reward of 3 after four days from today.\n * Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.\n\n* * *"}, {"input": "5 3\n 1 2\n 1 3\n 1 4\n 2 1\n 2 3", "output": "10\n \n\n* * *"}, {"input": "1 1\n 2 1", "output": "0"}]
Print the maximum total reward that you can earn no later than M days from today. * * *
s314140056
Wrong Answer
p02948
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
IN1 = input() N, M = [int(x) for x in IN1.split()] IN2 = [[int(x) for x in input().split()] for _ in range(N)] # 戦略 残りj日のとき働くべき:j日より期限が短く、最大の報酬が得られるもの j = 1 E = 0 while j < M + 1: j_choices = [x for x in IN2 if x[0] <= j] # print(j_choices) # print(len(j_choices)) if len(j_choices) > 1: M = max([x[1] for x in j_choices]) j_choices = [x for x in j_choices if x[1] == M] m = min([x[0] for x in j_choices]) j_choice = [x for x in j_choices if x[0] == m][0] E = E + j_choice[1] IN2.remove(j_choice) elif len(j_choices) == 1: j_choice = j_choices[0] # print(j_choice) E = E + j_choice[1] IN2.remove(j_choice) j += 1 print(E)
Statement There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it. You can take and complete at most one of these jobs in a day. However, you cannot retake a job that you have already done. Find the maximum total reward that you can earn no later than M days from today. You can already start working today.
[{"input": "3 4\n 4 3\n 4 1\n 2 2", "output": "5\n \n\nYou can earn the total reward of 5 by taking the jobs as follows:\n\n * Take and complete the first job today. You will earn the reward of 3 after four days from today.\n * Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.\n\n* * *"}, {"input": "5 3\n 1 2\n 1 3\n 1 4\n 2 1\n 2 3", "output": "10\n \n\n* * *"}, {"input": "1 1\n 2 1", "output": "0"}]
Print the maximum total reward that you can earn no later than M days from today. * * *
s693956113
Wrong Answer
p02948
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
a, b, d = list(map(int, input().split())), [], 0 n, m = a[0], a[1] for i in range(n): b.append(list(map(int, input().split()))) b.sort(key=lambda x: (x[0], x[1])) for i in range(m): c = [] for j in range(len(b)): if m - i >= b[j][0]: c.append(b[j]) c = sorted(c, key=lambda x: x[1]) if len(c) < 1: break else: d += c[-1][1] b.remove(c[-1]) print(d)
Statement There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it. You can take and complete at most one of these jobs in a day. However, you cannot retake a job that you have already done. Find the maximum total reward that you can earn no later than M days from today. You can already start working today.
[{"input": "3 4\n 4 3\n 4 1\n 2 2", "output": "5\n \n\nYou can earn the total reward of 5 by taking the jobs as follows:\n\n * Take and complete the first job today. You will earn the reward of 3 after four days from today.\n * Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.\n\n* * *"}, {"input": "5 3\n 1 2\n 1 3\n 1 4\n 2 1\n 2 3", "output": "10\n \n\n* * *"}, {"input": "1 1\n 2 1", "output": "0"}]
Print the maximum total reward that you can earn no later than M days from today. * * *
s128240211
Runtime Error
p02948
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
n, m = map(int, input().split()) li = [list(map(int, input().split())) for i in range(n)] day = [0 for i in range(m)] li.sort(key=lambda x: x[0]) li.sort(key=lambda x: x[1], reverse=True) count = 0 li2 = [] for i in range(n): x = li[i][0] - 1 if x < m and len(li2) == 0: li2.append([x, x]) count += li[i][1] continue elif x >= m: continue if li2[0][0] > x: li2[0:0] = [[x, x]] count += li[i][1] if li2[0][1] + 1 == li2[1][0]: li2[0][1] = li2[1][0] del li2[1:2] continue elif li2[len(li2) - 1][1] < x: li2[len(li2) : len(li2)] = [[x, x]] count += li[i][1] if li2[len(li2) - 1][1] + 1 == li2[len(li2)][0]: li2[len(li2) - 1][1] = li2[len(li2)][0] li2.pop() continue a = 0 b = len(li2) - 1 while a != b: c = int((a + b) / 2) if li2[c][1] >= x: b = c else: a = c + 1 if li2[a][0] <= x and li2[a][1] == m - 1: continue elif li2[a][0] <= x: li2[a][1] += 1 count += li[i][1] if a != len(li2) - 1: if li2[a][1] + 1 == li2[a + 1][0]: li2[a][1] = li2[a + 1][0] del li2[a + 1 : a + 2] else: li2[a:a] = [[x, x]] count += li[i][1] if li2[a - 1][1] + 1 == li2[a][0] and li2[a][1] + 1 == li2[a + 1][0]: li2[a - 1][1] = li2[a + 1][1] del li2[a : a + 1] del li2[a : a + 1] elif li2[a - 1][1] + 1 == li2[a][0]: del li2[a : a + 1] elif li2[a][1] + 1 == li2[a + 1][0]: del li2[a + 1 : a + 2] print(count)
Statement There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it. You can take and complete at most one of these jobs in a day. However, you cannot retake a job that you have already done. Find the maximum total reward that you can earn no later than M days from today. You can already start working today.
[{"input": "3 4\n 4 3\n 4 1\n 2 2", "output": "5\n \n\nYou can earn the total reward of 5 by taking the jobs as follows:\n\n * Take and complete the first job today. You will earn the reward of 3 after four days from today.\n * Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.\n\n* * *"}, {"input": "5 3\n 1 2\n 1 3\n 1 4\n 2 1\n 2 3", "output": "10\n \n\n* * *"}, {"input": "1 1\n 2 1", "output": "0"}]
Print the maximum total reward that you can earn no later than M days from today. * * *
s189556442
Accepted
p02948
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N
import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 class BinaryIndexedTree: # http://hos.ac/slides/20140319_bit.pdf def __init__(self, size): """ :param int size: """ self._bit = [0] * size self._size = size def add(self, i, w): """ i 番目に w を加える :param int i: :param int w: :return: """ x = i + 1 while x <= self._size: self._bit[x - 1] += w x += x & -x def sum(self, i): """ 0 番目から i 番目までの合計 :param int i: :return: """ ret = 0 x = i + 1 while x > 0: ret += self._bit[x - 1] x -= x & -x return ret def __len__(self): return self._size N, M = list(map(int, sys.stdin.readline().split())) AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N)] AB.sort(key=lambda ab: (-ab[1], ab[0])) bit = BinaryIndexedTree(size=M) ans = 0 for a, b in AB: if M - a < 0: continue # 入れられる? cap = M - a - bit.sum(M - a) + 1 if cap > 0: ans += b # どこに入れよう? ok = -1 ng = M - a while abs(ok - ng) > 1: mid = (ok + ng) // 2 if mid - bit.sum(mid) + 1 != cap: ok = mid else: ng = mid bit.add(ok + 1, 1) print(ans)
Statement There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it. You can take and complete at most one of these jobs in a day. However, you cannot retake a job that you have already done. Find the maximum total reward that you can earn no later than M days from today. You can already start working today.
[{"input": "3 4\n 4 3\n 4 1\n 2 2", "output": "5\n \n\nYou can earn the total reward of 5 by taking the jobs as follows:\n\n * Take and complete the first job today. You will earn the reward of 3 after four days from today.\n * Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.\n\n* * *"}, {"input": "5 3\n 1 2\n 1 3\n 1 4\n 2 1\n 2 3", "output": "10\n \n\n* * *"}, {"input": "1 1\n 2 1", "output": "0"}]
If it is not possible to untie all of the N-1 knots, print `Impossible`. If it is possible to untie all of the knots, print `Possible`, then print another N-1 lines that describe a possible order to untie the knots. The j-th of those N-1 lines should contain the index of the knot that is untied in the j-th operation. Here, the index of the knot connecting piece i and piece i+1 is i. If there is more than one solution, output any. * * *
s999756816
Accepted
p04035
The input is given from Standard Input in the following format: N L a_1 a_2 ... a_n
def main22(): strbuf = input("") strbufs = strbuf.split() buf = [] for i in range(2): buf.append(int(strbufs[i])) strbuf = input("") strbufs = strbuf.split() buf2 = [] for i in range(buf[0]): buf2.append(int(strbufs[i])) if buf[0] == 2: if buf2[0] + buf2[1] >= buf[1]: print("Possible") print(1) else: print("Impossible") else: point = -1 for i in range((buf[0] - 1)): if buf2[i] + buf2[i + 1] >= buf[1]: point = i + 1 break if point == -1: print("Impossible") else: print("Possible") if point != 1: for i in range(point - 1): print(i + 1) if point != buf[0] - 1: for i in range(buf[0] - 1, point, -1): print(i) print(point) if __name__ == "__main__": main22()
Statement We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
[{"input": "3 50\n 30 20 10", "output": "Possible\n 2\n 1\n \n\nIf the knot 1 is untied first, the knot 2 will become impossible to untie.\n\n* * *"}, {"input": "2 21\n 10 10", "output": "Impossible\n \n\n* * *"}, {"input": "5 50\n 10 20 30 40 50", "output": "Possible\n 1\n 2\n 3\n 4\n \n\nAnother example of a possible solution is 3, 4, 1, 2."}]
If it is not possible to untie all of the N-1 knots, print `Impossible`. If it is possible to untie all of the knots, print `Possible`, then print another N-1 lines that describe a possible order to untie the knots. The j-th of those N-1 lines should contain the index of the knot that is untied in the j-th operation. Here, the index of the knot connecting piece i and piece i+1 is i. If there is more than one solution, output any. * * *
s252684375
Wrong Answer
p04035
The input is given from Standard Input in the following format: N L a_1 a_2 ... a_n
print("impossible")
Statement We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
[{"input": "3 50\n 30 20 10", "output": "Possible\n 2\n 1\n \n\nIf the knot 1 is untied first, the knot 2 will become impossible to untie.\n\n* * *"}, {"input": "2 21\n 10 10", "output": "Impossible\n \n\n* * *"}, {"input": "5 50\n 10 20 30 40 50", "output": "Possible\n 1\n 2\n 3\n 4\n \n\nAnother example of a possible solution is 3, 4, 1, 2."}]
If it is not possible to untie all of the N-1 knots, print `Impossible`. If it is possible to untie all of the knots, print `Possible`, then print another N-1 lines that describe a possible order to untie the knots. The j-th of those N-1 lines should contain the index of the knot that is untied in the j-th operation. Here, the index of the knot connecting piece i and piece i+1 is i. If there is more than one solution, output any. * * *
s665188217
Runtime Error
p04035
The input is given from Standard Input in the following format: N L a_1 a_2 ... a_n
N, L = map(int, input().split()) a = [map(int, input().split())] b = 0 c = 0 for i in range(N-1): if a[i] + a[i+1] >= L: print("Possible") b = 1 c = i break else: print("Impossible") if b = 1: for i in range(c+1): print(i+1) for i in range(N, c+1, -1): print(i+1)
Statement We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
[{"input": "3 50\n 30 20 10", "output": "Possible\n 2\n 1\n \n\nIf the knot 1 is untied first, the knot 2 will become impossible to untie.\n\n* * *"}, {"input": "2 21\n 10 10", "output": "Impossible\n \n\n* * *"}, {"input": "5 50\n 10 20 30 40 50", "output": "Possible\n 1\n 2\n 3\n 4\n \n\nAnother example of a possible solution is 3, 4, 1, 2."}]
If it is not possible to untie all of the N-1 knots, print `Impossible`. If it is possible to untie all of the knots, print `Possible`, then print another N-1 lines that describe a possible order to untie the knots. The j-th of those N-1 lines should contain the index of the knot that is untied in the j-th operation. Here, the index of the knot connecting piece i and piece i+1 is i. If there is more than one solution, output any. * * *
s755849830
Runtime Error
p04035
The input is given from Standard Input in the following format: N L a_1 a_2 ... a_n
N, M = map(int, input().split()) x = [] y = [] for i in range(1, M + 1): z = list(map(int, input().split())) x.append(z[0]) y.append(z[1]) a = [0] b = [1] * N for i in range(M): b[x[i] - 1] -= 1 b[y[i] - 1] += 1 if x[i] - 1 in a: a.append(y[i] - 1) if b[x[i] - 1] == 0: a.remove(x[i] - 1) c = 0 for i in range(len(a)): if b[a[i]] != 0: c += 1 print(c)
Statement We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
[{"input": "3 50\n 30 20 10", "output": "Possible\n 2\n 1\n \n\nIf the knot 1 is untied first, the knot 2 will become impossible to untie.\n\n* * *"}, {"input": "2 21\n 10 10", "output": "Impossible\n \n\n* * *"}, {"input": "5 50\n 10 20 30 40 50", "output": "Possible\n 1\n 2\n 3\n 4\n \n\nAnother example of a possible solution is 3, 4, 1, 2."}]
If it is not possible to untie all of the N-1 knots, print `Impossible`. If it is possible to untie all of the knots, print `Possible`, then print another N-1 lines that describe a possible order to untie the knots. The j-th of those N-1 lines should contain the index of the knot that is untied in the j-th operation. Here, the index of the knot connecting piece i and piece i+1 is i. If there is more than one solution, output any. * * *
s764097409
Runtime Error
p04035
The input is given from Standard Input in the following format: N L a_1 a_2 ... a_n
n,l=map(int,input().split()) r=list(map(int,input().split())) last=0;tiepoint=0 for i in range(n-1): if r[i]+r[i+1]>last: last=r[i]+r[i+1] tiepoint=i if last>=l:print("Possible") for i in range(n): if i==tiepoint:continue print(i) else:print("Impossible")
Statement We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
[{"input": "3 50\n 30 20 10", "output": "Possible\n 2\n 1\n \n\nIf the knot 1 is untied first, the knot 2 will become impossible to untie.\n\n* * *"}, {"input": "2 21\n 10 10", "output": "Impossible\n \n\n* * *"}, {"input": "5 50\n 10 20 30 40 50", "output": "Possible\n 1\n 2\n 3\n 4\n \n\nAnother example of a possible solution is 3, 4, 1, 2."}]
If it is not possible to untie all of the N-1 knots, print `Impossible`. If it is possible to untie all of the knots, print `Possible`, then print another N-1 lines that describe a possible order to untie the knots. The j-th of those N-1 lines should contain the index of the knot that is untied in the j-th operation. Here, the index of the knot connecting piece i and piece i+1 is i. If there is more than one solution, output any. * * *
s332477257
Accepted
p04035
The input is given from Standard Input in the following format: N L a_1 a_2 ... a_n
NL = input() NL = "".join(NL).rstrip("\n").split(" ") N = int(NL[0]) L = int(NL[1]) a = input() a = "".join(a).split(" ") for s in range(N - 1): if int(a[s]) + int(a[s + 1]) >= L: Last = s + 1 print("Possible") for s in range(N - 1): if s + 1 > Last: for j in range(N): if (N - 1 - j) == s: # print(Last) break print(N - 1 - j) break if s + 1 == Last: continue print(s + 1) print(Last) break if s == N - 2: print("Impossible")
Statement We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
[{"input": "3 50\n 30 20 10", "output": "Possible\n 2\n 1\n \n\nIf the knot 1 is untied first, the knot 2 will become impossible to untie.\n\n* * *"}, {"input": "2 21\n 10 10", "output": "Impossible\n \n\n* * *"}, {"input": "5 50\n 10 20 30 40 50", "output": "Possible\n 1\n 2\n 3\n 4\n \n\nAnother example of a possible solution is 3, 4, 1, 2."}]
Print the number, modulo 998244353, of sequences that satisfy the condition. * * *
s586339204
Runtime Error
p03066
Input is given from Standard Input in the following format: N X
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np """ ・累積和の到達地点集合ごとに見る ・type1:X未満で終わる ・type2:X+1以上2X未満 ・type3:2X以上、これはXが奇数の場合のみ """ MOD = 998244353 N, X = map(int, read().split()) def cumprod(arr, MOD): L = len(arr) Lsq = int(L**0.5 + 1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n - 1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n - 1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = N + 100 fact, fact_inv = make_fact(U, MOD) combN = fact[N] * fact_inv[: N + 1] % MOD * fact_inv[N::-1] % MOD def F1(N, X): # X未満で終わる場合 def mult(P, Q): # 多項式の積 dP = len(P) - 1 dQ = len(Q) - 1 if dP < dQ: dP, dQ = dQ, dP P, Q = Q, P R = np.zeros(dP + dQ + 1, np.int64) for n in range(dQ + 1): R[n : n + dP + 1] += Q[n] * P % MOD R %= MOD return R[:X] def power(P, n): if n == 0: return np.array([1], dtype=np.int64) Q = power(P, n // 2) Q = mult(Q, Q) return mult(P, Q) if n & 1 else Q P = np.array([1, 1, 1], np.int64) Q = power(P, N) return Q.sum() % MOD def F2(N, X): U = N + 100 fact, fact_inv = make_fact(U, MOD) combN = fact[N] * fact_inv[: N + 1] % MOD * fact_inv[N::-1] % MOD x = np.zeros(N + 1, np.int64) # X+1+2nで終わる場合 for n in range(X): m = (X - 1) - (2 + 2 * n) if m < 0: break # 2+2n -> X-1に含まれる2の回数ごとに two = np.arange(m // 2 + 1, dtype=np.int64) one = m - 2 * two coef = fact[one + two] * fact_inv[one] % MOD * fact_inv[two] % MOD rest = N - one - two - (2 * n + 2) ind = rest >= 0 rest = rest[ind] coef = coef[ind] x[rest] += coef x %= MOD return (x * combN % MOD).sum() % MOD def F3(N, X): U = N + 100 fact, fact_inv = make_fact(U, MOD) combN = fact[N] * fact_inv[: N + 1] % MOD * fact_inv[N::-1] % MOD # 2X以上の偶数。Xは奇数で、+2を連打している場合 if X % 2 == 0: return 0 if X > N: return 0 n = N - X + 1 return combN[:n].sum() % MOD answer = (F1(N, X) + F2(N, X) + F3(N, X)) % MOD print(answer)
Statement Find the number, modulo 998244353, of sequences of length N consisting of 0, 1 and 2 such that none of their contiguous subsequences totals to X.
[{"input": "3 3", "output": "14\n \n\n14 sequences satisfy the condition:\n(0,0,0),(0,0,1),(0,0,2),(0,1,0),(0,1,1),(0,2,0),(0,2,2),(1,0,0),(1,0,1),(1,1,0),(2,0,0),(2,0,2),(2,2,0)\nand (2,2,2).\n\n* * *"}, {"input": "8 6", "output": "1179\n \n\n* * *"}, {"input": "10 1", "output": "1024\n \n\n* * *"}, {"input": "9 13", "output": "18402\n \n\n* * *"}, {"input": "314 159", "output": "459765451"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s429348150
Accepted
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# H, W = IL() maze = SLs(H) count = 0 for item in maze: for i in item: if i == ".": count += 1 dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] d = [[-1 for j in range(W)] for i in range(H)] d[0][0] = 0 q = deque([(0, 0)]) while q: x, y = q.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0 <= nx < W and 0 <= ny < H: if maze[ny][nx] == ".": if d[ny][nx] == -1: d[ny][nx] = d[y][x] + 1 q.append((nx, ny)) if d[H - 1][W - 1] == -1: print(-1) else: print(count - d[H - 1][W - 1] - 1)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s358996205
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
from collections import deque h,w=map(int,input().split()) field=["#" for i in range(w+2)]+[["#"]+list(input())+["#"] for i in range(h)]+["#" for i in range(w+2)] queue=deque([[1,1]]) cost=[[50000 for i in range(w)]for j in range(h)] cost[0][0]=0 while queue: now=queue.popleft() for i in [(-1,-1),(-1,1),(1,1),(1,-1)]: if field[now[0]+i[0]][now[1]+i[1]]=="#":continue if cost[now[0]+i[0]-1][now[1]+i[1]-1]!=50000 if cost[now[0]+i[0]-1][now[1]+i[1]-1]>cost[now[0]-1][now[1]-1]+1: cost[now[0]+i[0]-1][now[1]+i[1]-1]=cost[now[0]-1][now[1]-1]+1 cnt=0 for i in range(h+2): for j in range(w+2): if field[i][j]=="#":cnt+=1 cnt-=(h+w)*2+4 blackable=h*w-cnt if cost[-1][-1]==50000:print(-1) else: print(blackable-cost[-1][-1])
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s982130757
Wrong Answer
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
import sys sys.setrecursionlimit(10000000) H, W = [int(x) for x in input().split()] A = [] temp = 0 for i in range(H): s = input() A.append(s) for j in range(W): if s[j] == ".": temp += 1 # print(H,W) visited = [[0 for j in range(W)] for i in range(H)] visited[0][0] = 1 pointer = 0 ans = 10000000000000000000 def bfs(i, j, count): global ans global pointer # print(i,j,count) if j + 1 <= W - 1: if A[i][j + 1] == "." and visited[i][j + 1] == 0: visited[i][j + 1] = 1 bfs(i, j + 1, count + 1) if 0 <= j - 1: if A[i][j - 1] == "." and visited[i][j - 1] == 0: visited[i][j - 1] = 1 bfs(i, j - 1, count + 1) if i + 1 <= H - 1: # print(i+1,H-1,100000) if A[i + 1][j] == "." and visited[(i + 1)][j] == 0: visited[(i + 1)][j] = 1 bfs(i + 1, j, count + 1) if 0 <= i - 1: if A[i - 1][j] == "." and visited[(i - 1)][j] == 0: visited[(i - 1)][j] = 1 bfs(i - 1, j, count + 1) if i == H - 1 and j == W - 1: ans = min(ans, count) # print(ans) pointer = 1 visited[-1][-1] = 0 bfs(0, 0, 1) # print(A) # print(visited) if pointer == 0: print("-1") else: print(temp - ans)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s947138608
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
H, W = map(int, input().split()) s = [list(input()) for _ in range(H)] black = 0 for tate in s: for yoko in tate: if yoko == "#": black += 1 def search(y, x, H, W, s): child = [] if y < H - 1: if s[y + 1][x] == ".": child.append([y + 1, x]) if 0 < y: if s[y - 1][x] == ".": child.append([y - 1, x]) if 0 < x: if s[y][x - 1] == ".": child.append([y, x - 1]) if x < W - 1: if s[y][x + 1] == ".": child.append([y, x + 1]) return child def dfs(y, x, cnt, H, W, s): node_to_visit = search(y, x, H, W, s) flag = True while flag: cnt += 1 tmp = [] tmp2 = [] for next_point in node_to_visit: t = next_point[0] u = next_point[1] if t != y or u != x: tmp = search(u, t, H, W, s) tmp2 += tmp node_to_visit = tmp2 if [H - 1, W - 1] in node_to_visit: white = cnt flag = False break ans = H * W - white - black - 2 print(white, black, ans) dfs(0, 0, 0, H, W, s)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s542307014
Wrong Answer
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
import numpy as np temp = input() H, W = temp.split() H = int(H) W = int(W) pref = np.zeros((H, W)) for i in range(H): row = input() for j in range(W): if row[j] == ".": pref[i][j] = 1 else: pref[i][j] = 0 totalw = np.count_nonzero(pref) a = np.zeros((H, W)) quere = [] quere.append(0) while quere != []: locas = quere[0] tempscore = (H + 1) * (W + 1) if locas % W > 0: left = locas - 1 if a[(left // W)][(left % W)] == 0 and pref[(left // W)][(left % W)] == 1: if left not in quere: quere.append(left) elif a[(left // W)][(left % W)] > 0: tempscore = min(tempscore, a[(left // W)][(left % W)]) if locas % W < W - 1: right = locas + 1 if a[(right // W)][(right % W)] == 0 and pref[(right // W)][(right % W)] == 1: if right not in quere: quere.append(right) elif a[(right // W)][(right % W)] > 0: tempscore = min(tempscore, a[(right // W)][(right % W)]) if locas // W > 0: up = locas - W if a[(up // W)][(up % W)] == 0 and pref[(up // W)][(up % W)] == 1: if up not in quere: quere.append(up) elif a[(up // W)][(up % W)] > 0: tempscore = min(tempscore, a[(up // W)][(up % W)]) if (locas // W) < (H - 1): down = locas + W if a[(down // W)][(down % W)] == 0 and pref[(down // W)][(down % W)] == 1: if down not in quere: quere.append(down) elif a[(down // W)][(down % W)] > 0: tempscore = min(tempscore, a[(down // W)][(down % W)]) if locas == 0: tempscore = 0 a[(locas // W)][(locas % W)] = tempscore + 1 quere.pop(0) leng = a[H - 1][W - 1] score = totalw - leng print(int(score))
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s390443095
Wrong Answer
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
print(-1)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s862723582
Accepted
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
############################################################################### from sys import stdout from bisect import bisect_left as binl from copy import copy, deepcopy from collections import defaultdict mod = 1 def intin(): input_tuple = input().split() if len(input_tuple) <= 1: return int(input_tuple[0]) return tuple(map(int, input_tuple)) def intina(): return [int(i) for i in input().split()] def intinl(count): return [intin() for _ in range(count)] def modadd(x, y): global mod return (x + y) % mod def modmlt(x, y): global mod return (x * y) % mod def lcm(x, y): while y != 0: z = x % y x = y y = z return x def combination(x, y): assert x >= y if y > x // 2: y = x - y ret = 1 for i in range(0, y): j = x - i i = i + 1 ret = ret * j ret = ret // i return ret def get_divisors(x): retlist = [] for i in range(1, int(x**0.5) + 3): if x % i == 0: retlist.append(i) retlist.append(x // i) return retlist def get_factors(x): retlist = [] for i in range(2, int(x**0.5) + 3): while x % i == 0: retlist.append(i) x = x // i retlist.append(x) return retlist def make_linklist(xylist): linklist = {} for a, b in xylist: linklist.setdefault(a, []) linklist.setdefault(b, []) linklist[a].append(b) linklist[b].append(a) return linklist def calc_longest_distance(linklist, v=1): distance_list = {} distance_count = 0 distance = 0 vlist_previous = [] vlist = [v] nodecount = len(linklist) while distance_count < nodecount: vlist_next = [] for v in vlist: distance_list[v] = distance distance_count += 1 vlist_next.extend(linklist[v]) distance += 1 vlist_to_del = vlist_previous vlist_previous = vlist vlist = list(set(vlist_next) - set(vlist_to_del)) max_distance = -1 max_v = None for v, distance in distance_list.items(): if distance > max_distance: max_distance = distance max_v = v return (max_distance, max_v) def calc_tree_diameter(linklist, v=1): _, u = calc_longest_distance(linklist, v) distance, _ = calc_longest_distance(linklist, u) return distance class UnionFind: def __init__(self, n): self.parent = [i for i in range(n)] def root(self, i): if self.parent[i] == i: return i self.parent[i] = self.root(self.parent[i]) return self.parent[i] def unite(self, i, j): rooti = self.root(i) rootj = self.root(j) if rooti == rootj: return if rooti < rootj: self.parent[rootj] = rooti else: self.parent[rooti] = rootj def same(self, i, j): return self.root(i) == self.root(j) ############################################################################### def main(): h, w = intin() slistlist = ["#" * (w + 2)] slistlist.extend(["#" + input() + "#" for _ in range(h)]) slistlist.append("#" * (w + 2)) clistlist = [] for i in range(h + 2): clistlist.append([False] * (w + 2)) white_count = 0 for slist in slistlist: for s in slist: if s == ".": white_count += 1 paths = {(1, 1): 1} while paths: next_paths = defaultdict(lambda: float("inf")) for p, c in paths.items(): if slistlist[p[0] + 1][p[1]] == "." and not clistlist[p[0] + 1][p[1]]: next_paths[(p[0] + 1, p[1])] = min(c + 1, next_paths[(p[0] + 1, p[1])]) clistlist[p[0] + 1][p[1]] = True if slistlist[p[0] - 1][p[1]] == "." and not clistlist[p[0] - 1][p[1]]: next_paths[(p[0] - 1, p[1])] = min(c + 1, next_paths[(p[0] - 1, p[1])]) clistlist[p[0] - 1][p[1]] = True if slistlist[p[0]][p[1] + 1] == "." and not clistlist[p[0]][p[1] + 1]: next_paths[(p[0], p[1] + 1)] = min(c + 1, next_paths[(p[0], p[1] + 1)]) clistlist[p[0]][p[1] + 1] = True if slistlist[p[0]][p[1] - 1] == "." and not clistlist[p[0]][p[1] - 1]: next_paths[(p[0], p[1] - 1)] = min(c + 1, next_paths[(p[0], p[1] - 1)]) clistlist[p[0]][p[1] - 1] = True paths = next_paths if (h, w) in paths: print(white_count - paths[(h, w)]) return print(-1) if __name__ == "__main__": main()
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s053347144
Wrong Answer
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
# coding: UTF-8 # @document_it from collections import deque def document_it(func): def new_function(*args, **kwargs): print("Running function:", func.__name__) print("Positional arguments:", args) print("Kewword arguments:", kwargs) result = func(*args, **kwargs) print("Result:", result) return result return new_function ########################### # @document_it # O(1)のはず def nb(i, j, H, W): ans = [] a = i + 1 b = i - 1 c = j + 1 d = j - 1 if a >= 0 and a <= H - 1: ans.append((a, j)) if b >= 0 and b <= H - 1: ans.append((b, j)) if c >= 0 and c <= W - 1: ans.append((i, c)) if d >= 0 and d <= W - 1: ans.append((i, d)) return ans def e(): # 入力データ整理 dist = {} white = {} wtotal = 0 H, W = map(int, input().split()) for i in range(H): row = input() for j in range(W): dist[(i, j)] = -1 if row[j] == ".": white[(i, j)] = True wtotal += 1 else: white[(i, j)] = False # リンク作成 # tuple -> [tuple] # リンクの数は最大でも頂点の4倍なのでO(HW) link = {} for i in range(H): for j in range(W): link[(i, j)] = [] if not white[(i, j)]: continue else: nlist = nb(i, j, H, W) for p in nlist: if white[p]: link[(i, j)].append(p) q = deque() dist[(0, 0)] = 1 q.append((0, 0)) while q: v = q.popleft() for w in link[v]: if dist[w] == -1: dist[w] = dist[v] + 1 q.append(w) # print(w,dist[w]) if dist[(H - 1, W - 1)] != -1: ans = wtotal - dist[(H - 1, W - 1)] else: ans = -1 print(wtotal) print(dist[(H - 1, W - 1)]) print(ans) ########################### if __name__ == "__main__": e()
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s288922953
Wrong Answer
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
from collections import deque nNM = [] nNM = input().rstrip().split(" ") nH = int(nNM[0]) nW = int(nNM[1]) nTmp = [0 for i in range(nW)] """ nData = [[0 for i in range(nN)] for j in range(nM)] nS=[0 for i in range(2)] nG=[0 for i in range(2)] """ graph = {} kyori = {} checked = {} nWallCnt = 0 for i in range(nH): nTmp = input() # print(nTmp) for i2 in range(nW): nPoi = "%d-%d" % (i, i2) graph[nPoi] = [] kyori[nPoi] = float("inf") checked[nPoi] = 0 if i == 0 and i2 == 0: nStart = "%d-%d" % (0, 0) kyori[nPoi] = int(0) continue elif i == nH - 1 and i2 == nW - 1: nGoal = "%d-%d" % (nH - 1, nW - 1) continue elif nTmp[i2] == "#": nWall = "%d-%d" % (i, i2) nWallCnt += 1 checked[nPoi] = 1 else: if i - 1 >= 0: graph[nPoi].append("%d-%d" % (i - 1, i2)) if i + 1 < nH: graph[nPoi].append("%d-%d" % (i + 1, i2)) if i2 - 1 >= 0: graph[nPoi].append("%d-%d" % (i, i2 - 1)) if i2 + 1 < nW: graph[nPoi].append("%d-%d" % (i, i2 + 1)) root_queue = deque() root_queue += graph[nStart] nCount = len(graph[nStart]) for i in range(nCount): kyori[(graph[nStart][i])] = 1 nFlag = 0 while root_queue: nPoi2 = root_queue.popleft() if checked[nPoi2] == 0: if nPoi2 == nGoal: nFlag = 1 break else: root_queue += graph[nPoi2] for i in range(len(graph[nPoi2])): nTmpCount = kyori[nPoi2] + 1 if kyori[(graph[nPoi2][i])] > nTmpCount: kyori[(graph[nPoi2][i])] = nTmpCount checked[nPoi2] = 1 if nFlag == 0: print("-1") else: nTmp = kyori[nGoal] + 1 nTotal = nH * nW nAns = nTotal - (nTmp + nWallCnt) print(nAns)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s636583362
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
from collections import deque def bfs(): d = [[float('inf')]* w for i in range(h)] dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] que = deque([]) que.append((sx, sy)) d[sx][sy] = 0 while que: p = que.popleft() if p[0] == gx and p[1] == gy: break for i in range(4): nx = p[0] + dx[i] ny = p[1] + dy[i] if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != '#' and d[nx][ny] == float('inf'): que.append((nx, ny)) d[nx][ny] = d[p[0]][p[1]] + 1 return d[gx][gy] h, w = map(int, input().split()) maze = [list(input()) for i in range(h)] sx, sy = 0, 0 gx, gy = h-1, w-1 white = 0 for i in range(h): for j in range(w): if maze[i][j] == '.': white += 1 res = bfs() if 0 < res < float('inf'): print(white - res - 1) else:
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s040003660
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
from collections import deque H, W = map(int, input().split(" ")) S = [list(input()) for i in range(H)] S[0][0] = 1 next = deque([[0, 0]]) ans = H * W while next: x, y = next.popleft() s = S[x][y] for i, j in [[1, 0], [0, 1], [-1, 0], [0, -1]]: if 0 <= x + i < H and 0 <= y + j < W and S[x + i][y + j] == ".": S[x + i][y + j] = s + 1 next.append([x + i, y + j]) for i in S: ans -= i.count("#") print(ans - S[H - 1][W - 1])
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s385241092
Accepted
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
from collections import deque, Counter import sys H, W = map(int, input().split()) count = 0 grid = ["s" for h in range(H)] for h in range(H): grid[h] = list(input()) tmp_count = Counter(grid[h])["#"] if tmp_count == W: print(-1) sys.exit() count += tmp_count deq = deque([(0, 0)]) visited = [[-1 for w in range(W)] for h in range(H)] visited[0][0] = 0 route = 0 while deq: for _ in range(len(deq)): h, w = deq.popleft() # print(h, w) if (h, w) == (H - 1, W - 1): print(H * W - visited[h][w] - 1 - count) sys.exit() for j, k in ([-1, 0], [0, -1], [0, 1], [1, 0]): new_h, new_w = h + j, w + k if 0 <= new_h <= H - 1 and 0 <= new_w <= W - 1: if grid[new_h][new_w] != "#" and visited[new_h][new_w] == -1: visited[new_h][new_w] = visited[h][w] + 1 deq.append((new_h, new_w)) print(-1)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s596397705
Wrong Answer
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
h, w = map(int, input().split()) A = [list("#" * (w + 2))] count_sharp = 0 for _ in range(h): C = list(input()) count_sharp += C.count("#") A.append(["#"] + C + ["#"]) A.append(list("#") * (w + 2)) matrix = [[] for _ in range(10000)] for i in range(h + 1): for j in range(w + 1): if A[i][j] == ".": if A[i - 1][j] == ".": matrix[(i - 1) * 100 + j].append(i * 100 + j) elif A[i][j - 1] == ".": matrix[i * 100 + j - 1].append(i * 100 + j) elif A[i + 1][j] == ".": matrix[(i + 1) * 100 + j].append(i * 100 + j) elif A[i][j + 1] == ".": matrix[i * 100 + j + 1].append(i * 100 + j) # print(matrix) def solver(matrix, h, w, count_): depth = 0 path = [10000000] * 10000 path[101] = 0 stack = [] stack.append(101) reached = [101] while len(stack) > 0: depth += 1 for _ in range(len(stack)): val = stack.pop(0) for j in matrix[val]: if j not in set(reached): path[j] = min(depth, path[j]) reached.append(j) stack.append(j) # print(path) # print(path[h*100 + w] + 1) if path[h * 100 + w] == 10000000: print(-1) else: print(h * w - path[h * 100 + w] - 1 - count_) solver(matrix, h, w, count_sharp)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s502534954
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
import sys h,w = [int(i) for i in input().split()] sys.setrecursionlimit(100000) s = [['#']*(w+2)] + [['#']+list(input())+['#'] for _ in range(h)] + [['#']*(w+2)] #print(s) cost = [[-1 if s[y][x] == '#' else float('inf') for x in range(w+2)] for y in range(h+2)] cost[1][1] = 0 #print(cost) move_que = [[1,1]] def list_flatten(nested_list): flat_list = [] fringe = [nested_list] while len(fringe) > 0: node = fringe.pop(0) if isinstance(node, list): fringe = node + fringe else: flat_list.append(node) return(flat_list) def move(place): y,x = place if cost[y+1][x] != -1 or cost[y+1][x] != float('inf'): cost[y+1][x] = cost[y][x]+1 move_que.append([y+1,x]) if cost[y-1][x] != -1 or cost[y-1][x] != float('inf'): cost[y-1][x] = cost[y][x]+1 move_que.append([y-1,x]) if cost[y][x+1] != -1 or cost[y][x+1] != float('inf'): cost[y][x+1] = cost[y][x]+1 move_que.append([y,x+1]) if cost[y][x-1] != -1 or cost[y][x-1] != float('inf'): cost[y][x-1] = cost[y][x]+1 move_que.append([y,x-1]) while len(move_que) != 0: move(move_que[0]) move_que = move_que[1:] #print(cost) if cost[h][w] == float('inf'): print(-1) else: while_num = list_flatten(s).count('.') print(while_num - (cost[h][w]+1))
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s962499735
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
from collections import deque import numpy as np import sys #input = sys.stdin.readline sys.setrecursionlimit(5000) def get_adj_tiles(v): i, j = v res = [(i-1, j), (i+1, j), (i, j-1), (i, j+1)] return res def bfs(point): visited = [] que = deque() que.append((point, 1)) while len(que) > 0: v, depth = que.popleft() visited.append(v) adjs = get_adj_tiles(v) for a in adjs: if field[a[0]][a[1]] == '.' and a not in visited: if a == (H, W): return depth + 1 else: que.append((a, depth+1)) if len(que) == 0: return 0 H, W = list(map(int, input().split())) field = [['#'] * (W + 2) for _ in range(H + 2)] for i in range(H): values = list(input()) field[i+1][1:-1] = values number_of_whites = 0 for i in range(H+2): for j in range(W+2): if field[i][j] == '.': number_of_whites += 1 shortest_path = bfs((1, 1)) if shortest_path > 0: print(number_of_whites - shortest_path) else: print(-1)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s073416627
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
import queue H , W = list(map(int, input().split())) S = [input() for _ in range(H)] Sum = 0 for i in range(H): for j in range(W): Sum += (S[i][j] == '#') start = [1, 1, 1] visited = [[0] * W for _ in range(H)] visited[0][0] = 1 Q = queue.Queue() Q.put(start) now = start while(now[:2] != [H, W] and not Q.empty()): now = Q.get() for i in range(2): for j in range(2): h = now[0] + ((-1) ** i + (-1) ** j) // 2 w = now[1] + ((-1) ** i - (-1) ** j) // 2 if(1 <= h and h <= H and 1 <= w and w <= W and visited[h - 1][w - 1] == 0 and S[h - 1][w - 1] == '.'): visited[h - 1][w - 1] = 1 Q.put([h, w, now[2] + 1]) if(now[:2] == [H, W]): print(H * W - Sum - now[2]) else: print(-1) h = now[0] + (-1) ** i w = now[1] + (-1) ** j if(1 <= h and h <= H and 1 <= w and w <= W and visited[h - 1][w - 1] == 0): visited[h - 1][w - 1] = 1 Q.put([h, w, now[2] + 1]) if(now[:2] == [H, W]): print(H * W - Sum - now[2]) else: print(-1)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s745350501
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
from collections import deque h,w = map(int,input().split()) d = [input() for i in range(h)] count = 0 for i in range(h): for j in range(w): if d[i][j] == '#': count+=1 visited = [[0 for i in range(w)] for i in range(h)] def bfs(sy,sx,gy,gx): que = deque() que.append((sy,sx)) visited[sy][sx] = 0 while que: y,x = que.popleft() if y == gy and x == gx: return visited[y][x] for dy,dx in [(-1,0),(1,0),(0,-1),(0,1)]: ny,nx = y+dy, x+dx if ny < 0 or nx < 0 or ny >= h or nx >= w: continue elif d[ny][nx] == '#': continue elif visited[ny][nx] != 0: continue else: visited[ny][nx] = visited[y][x] + 1 que.append((ny,nx)) return visited[gy][gx] ans = bfs(0,0,h-1,w-1) if ans = 0: print(-1) exit() print(h*w - ans - count - 1)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s722111074
Wrong Answer
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
import heapq class edge: def __init__(self, to, cost): self.to = to self.cost = cost H, W = map(int, input().split()) G = [list() for i in range(H * W)] s = [] for j in range(H): s.extend(input()) for i in range(H): for j in range(W): if j < W - 1 and s[W * i + j] == "." and s[W * i + j + 1] == ".": G[W * i + j].append(edge(W * i + j + 1, 1)) if i < H - 1 and s[W * i + j] == "." and s[W * i + j + W] == ".": G[W * i + j].append(edge(W * i + j + W, 1)) def dijkstra(o): d = [float("inf") for i in range(H * W)] d[o] = 0 hq = [] prev = [[] for i in range(H * W)] heapq.heappush(hq, (0, o)) while hq: p = heapq.heappop(hq) v = p[1] if d[v] < p[0]: continue for i in G[v]: if d[i.to] > d[v] + i.cost: d[i.to] = d[v] + i.cost prev[i.to] = prev[v] + [str(sorted([v, i.to]))] heapq.heappush(hq, (d[i.to], i.to)) return d, prev ans = set() for i in range(1): tmp = dijkstra(i)[0] if tmp[H * W - 1] == float("inf"): print(-1) else: # -1:start print(H * W - s.count("#") - 1 - tmp[H * W - 1])
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s399271033
Accepted
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
H, W = map(int, input().split()) c = [["#"] * (W + 2) for _ in range(H + 2)] dots = 0 for y in range(H): c[y + 1] = "#", *list(input()), "#" dots += c[y + 1].count(".") inf = H * W m = [[inf] * W for _ in range(H)] m[0][0] = 0 drs = [[-1, 0], [1, 0], [0, -1], [0, 1]] s = 0 yx = [[1, 1]] notgoal = True while notgoal and yx: yx2 = [] s += 1 for y, x in yx: for dy, dx in drs: x2 = x + dx y2 = y + dy if c[y2][x2] == "." and m[y2 - 1][x2 - 1] == inf: m[y2 - 1][x2 - 1] = s if (y2, x2) == (H, W): notgoal = False else: yx2.append([y2, x2]) yx = yx2 if notgoal: print("-1") else: print(dots - s - 1)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s479238646
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
print(-1
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s306902079
Accepted
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
H, W = tuple(map(int, input().split())) s = [input() for _ in range(H)] q = [(0, 0, 0)] h = {(0, 0)} opt = float("inf") while q: i, j, k = q.pop(0) if i == H - 1 and j == W - 1: opt = k break a = [ (u, v) for u, v in ((i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)) if 0 <= u < H and 0 <= v < W and s[u][v] == "." and (u, v) not in h ] q += [(u, v, k + 1) for u, v in a] h |= set(a) print(max(-1, sum(t.count(".") for t in s) - opt - 1))
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s909785325
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
H, W = map(int, input().split()) Ss = [] white_count = 0 for i in range(H): s = list(input()) for masu in s: if masu == ".": white_count += 1 Ss.append(s) # print('white_count', white_count) def search(): global Ss_hosu # global min_hosu Ss_hosu[0][0] = 1 que = [[0, 0]] while len(que) > 0: x, y = que.pop(0) my_value = Ss_hosu[y][x] for dx, dy in [[1, 0], [-1, 0], [0, 1], [0, -1]]: if 0 <= x + dx <= W - 1 and 0 <= y + dy <= H - 1: if Ss[y + dy][x + dx] == "." and Ss_hosu[y + dy][x + dx] is None: Ss_hosu[y + dy][x + dx] = my_value + 1 que.append([x + dx, y + dy]) # Ss_hosu[y][x] = value # if x == W-1 and y == H-1: # min_hosu = value # for dx, dy in [[1,0], [-1,0], [0,1], [0,-1]]: # if 0 <= x+dx <= W-1 and 0 <= y+dy <= H-1: # if Ss[y+dy][x+dx] == '.' and Ss_hosu[y+dy][x+dx] is None: # search(x+dx, y+dy, value=value+1) Ss_hosu = [[None for _ in range(W)] for _ in range(H)] search() min_hosu = Ss_hosu[H - 1][W - 1] # for s in Ss_hosu: # print(s) # print('min_hosu', min_hosu) print(white_count - min_hosu)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s714578966
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
from collections import deque import numpy as np import sys #input = sys.stdin.readline sys.setrecursionlimit(5000) def bfs(point, field, target, H, W): visited = [[-1 for _ in range(W+2)] for _ in range(H+2)] visited[point[0]][point[1]] = 1 que = deque() que.append(point) while True: v = que.popleft() depth = visited[v[0]][v[1]] for a in [(v[0]-1, v[1]), (v[0]+1, v[1]), (v[0], v[1]-1), (v[0], v[1]+1)]: if field[a[0]][a[1]] == 0 and visited[a[0]][a[1]] == -1: visited[a[0]][a[1]] = 1 + depth if a == target: return visited[a[0]][a[1]] else: que.append(a) if len(que) == 0: return 0 def main() H, W = list(map(int, input().split())) target = (H, W) field = [[-1] * (W+2)] number_of_whites = 0 for _ in range(H): s = input() number_of_whites += s.count('.') field.append([-1] + [0 if c=='.' else -1 for c in s] + [-1]) field += [[-1] * (W+2)] shortest_path = bfs((1, 1), field, target, H, W) if shortest_path > 0: print(number_of_whites - shortest_path) else: print(-1) if __name__ == '__main__': main()
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s776265000
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
# coding: utf-8 # https://atcoder.jp/contests/abc088/tasks/abc088_d # 19:01-20:04 chudan # 20:17-20:30 done def main(): H, W = map(int, input().split()) INF = 10**10 n_white = 0 s = [[-1] * (W+2) for _ in range(H+2)] for i in range(H): for j, x in enumerate(input()): # white => 1, black => -1 s[i+1][j+1] = INF if x == "." else -1 n_white += 1 if x == "." else 0 s[1][1] = 0 fixed = set([]) while True: # 最短から貪欲に伸ばして行く x, y = H, W # init for i in range(1, H+1): for j in range(1, W+1): if s[i][j] != -1 and s[i][j] <= s[x][y] and "{}_{}".format(i, j) not in fixed: x, y = i, j fixed.add("{}_{}".format(x, y)) if x == H and y == W: shortest = s[x][y] break if s[x][y-1] != -1: s[x][y-1] = min(s[x][y]+1, s[x][y-1]) # fixed.add("{}_{}".format(x, y-1)) if s[x][y+1] != -1: s[x][y+1] = min(s[x][y]+1, s[x][y+1]) # fixed.add("{}_{}".format(x, y+1)) if s[x-1][y] != -1: s[x-1][y] = min(s[x][y]+1, s[x-1][y]) # fixed.add("{}_{}".format(x-1, y)) if s[x+1][y] != -1: s[x+1][y] = min(s[x][y]+1, s[x+1][y]) # fixed.add("{}_{}".format(x+1, y)) return n_white - (shortest + 1) if shortest < H*W else print(main())
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s520294000
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
#include <iostream> #include <string> #include <algorithm> #include <cmath> #include <cstdlib> #include <bitset> #include<vector> #include<utility> #include<fstream> #include<queue> #include <iomanip> #include<numeric> #include<set> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; #define rep(i,n) for(int i=0;i<n;i++) char ca; ll c, d = 0, e, i, j, k, h, w, a[55][55] = {}, b[55][55] = {},o,p; queue<i_i> q; bool dft(int s, int t, int u) { if (a[s][t] == 0)return false; if (b[s][t] != 0)return false; b[s][t] = u + 1; return true; } int main() { cin >> h >> w; for(j=1;j<=h;j++) for (i = 1; i <= w; i++) { cin >> ca; if (ca == '.') { a[i][j] = 1; d++; } else a[i][j] = 0; } q.push(make_pair(1, 1)); b[1][1] = 1; while (q.size() != 0) { o = q.front().first; p = q.front().second; if (dft(o + 1, p, b[o][p])) q.push(make_pair(o + 1, p)); if (dft(o, p+1, b[o][p])) q.push(make_pair(o, p+1)); if (dft(o -1, p, b[o][p])) q.push(make_pair(o - 1, p)); if (dft(o, p-1, b[o][p])) q.push(make_pair(o, p-1)); q.pop(); } if (b[w][h] == 0)cout << -1; else cout << (d - b[w][h]); return 0; }
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s134808832
Accepted
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
R, C = map(int, input().split()) mp = [[i for i in input().rstrip()] for i in range(R)] for i in range(R): mp[i] = list(mp[i]) ans = [[3000 for i in range(C)] for j in range(R)] ans[0][0] = 0 start = [0, 0] goal = [R - 1, C - 1] nsx = [1, 0, -1, 0] nsy = [0, 1, 0, -1] def bfs(graph, st, end): queue = [st] while queue: nw = queue.pop(0) if nw == end: return ans[end[0]][end[1]] else: for i in range(4): ns1 = nw[0] + nsx[i] ns2 = nw[1] + nsy[i] if ( (0 <= ns1) and (ns1 <= (R - 1)) and (0 <= ns2) and (ns2 <= (C - 1)) and ans[ns1][ns2] == 3000 and mp[ns1][ns2] == "." ): ans[ns1][ns2] = ans[nw[0]][nw[1]] + 1 queue.append([ns1, ns2]) return bfs(mp, start, goal) if ans[R - 1][C - 1] == 3000: print("-1") else: max_ans = R * C - ans[R - 1][C - 1] - 1 for i in range(R): for j in range(C): if mp[i][j] == "#": max_ans -= 1 print(max_ans)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s246422222
Runtime Error
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
import copy n, hp = map(int, input().split(" ")) la = [0 for i in range(n)] lb = [0 for i in range(n)] for i in range(n): la[i], lb[i] = map(int, input().split(" ")) cnt = 0 ma = max(la) lma = [i for i, x in enumerate(la) if x == ma] mib = 10**9 for i in lma: if lb[i] < mib: mib = lb[i] k = i tmp = copy.deepcopy(lb) while max(tmp) > ma: hp -= max(tmp) tmp.remove(max(tmp)) cnt += 1 if hp < 0: print(cnt) exit(0) if lb[k] > ma: hp += lb[k] if lb[k] > ma: hp -= lb[k] cnt += 1 if hp % ma == 0: print(cnt + int(hp / ma)) else: print(cnt + int(hp / ma) + 1)
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. * * *
s731307386
Wrong Answer
p03436
Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} : : s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
def main(): from collections import deque H, W = map(int, input().split()) s = [input() for _ in range(H)] already_black = sum(row.count("#") for row in s) dq = deque() dq.append((0, 0)) dist = [[-1] * W for _ in range(H)] dist[0][0] = 1 while dq: r, c = dq.popleft() if r == H - 1 and c == W - 1: break if ( r > 0 and s[r - 1][c] == "." and not (~dist[r - 1][c] and dist[r - 1][c] <= dist[r][c] + 1) ): dist[r - 1][c] = dist[r][c] + 1 dq.append((r - 1, c)) if ( c > 0 and s[r][c - 1] == "." and not (~dist[r][c - 1] and dist[r][c - 1] <= dist[r][c] + 1) ): dist[r][c - 1] = dist[r][c] + 1 dq.append((r, c - 1)) if ( r < H - 1 and s[r + 1][c] == "." and not (~dist[r + 1][c] and dist[r + 1][c] <= dist[r][c] + 1) ): dist[r + 1][c] = dist[r][c] + 1 dq.append((r + 1, c)) if ( c < W - 1 and s[r][c + 1] == "." and not (~dist[r][c + 1] and dist[r][c + 1] <= dist[r][c] + 1) ): dist[r][c + 1] = dist[r][c] + 1 dq.append((r, c + 1)) ans = H * W - (dist[H - 1][W - 1] + already_black) print(ans) if __name__ == "__main__": main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
statement We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
[{"input": "3 3\n ..#\n #..\n ...", "output": "2\n \n\nThe score 2 can be achieved by changing the color of squares as follows:\n\n![Explanation of Sample\n1](https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png)\n\n* * *"}, {"input": "10 37\n .....................................\n ...#...####...####..###...###...###..\n ..#.#..#...#.##....#...#.#...#.#...#.\n ..#.#..#...#.#.....#...#.#...#.#...#.\n .#...#.#..##.#.....#...#.#.###.#.###.\n .#####.####..#.....#...#..##....##...\n .#...#.#...#.#.....#...#.#...#.#...#.\n .#...#.#...#.##....#...#.#...#.#...#.\n .#...#.####...####..###...###...###..\n .....................................", "output": "209"}]
Print the AtCoDeer's maximum possible score. * * *
s140265469
Accepted
p03965
The input is given from Standard Input in the following format: s
N = input() p = N.count("p") print(len(N) // 2 - p)
Statement AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
[{"input": "gpg", "output": "0\n \n\nPlaying the same gesture as the opponent in each turn results in the score of\n0, which is the maximum possible score.\n\n* * *"}, {"input": "ggppgggpgg", "output": "2\n \n\nFor example, consider playing gestures in the following order: Rock, Paper,\nRock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three\nvictories and suffers one defeat, resulting in the score of 2, which is the\nmaximum possible score."}]
Print the AtCoDeer's maximum possible score. * * *
s391134406
Accepted
p03965
The input is given from Standard Input in the following format: s
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") AZ = "abcdefghijklmnopqrstuvwxyz" ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2, N + 1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) def base_10_to_n_without_0(X, n): X -= 1 if X // n: return base_10_to_n_without_0(X // n, n) + [X % n] return [X % n] #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# S = S() ans = 0 for s in S: if s == "g": ans -= 1 else: ans += 1 print(-ans // 2)
Statement AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
[{"input": "gpg", "output": "0\n \n\nPlaying the same gesture as the opponent in each turn results in the score of\n0, which is the maximum possible score.\n\n* * *"}, {"input": "ggppgggpgg", "output": "2\n \n\nFor example, consider playing gestures in the following order: Rock, Paper,\nRock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three\nvictories and suffers one defeat, resulting in the score of 2, which is the\nmaximum possible score."}]
Print the AtCoDeer's maximum possible score. * * *
s241928838
Accepted
p03965
The input is given from Standard Input in the following format: s
import sys, collections as cl, bisect as bs sys.setrecursionlimit(100000) input = sys.stdin.readline mod = 10**9 + 7 Max = sys.maxsize def l(): # intのlist return list(map(int, input().split())) def m(): # 複数文字 return map(int, input().split()) def onem(): # Nとかの取得 return int(input()) def s(x): # 圧縮 a = [] if len(x) == 0: return [] aa = x[0] su = 1 for i in range(len(x) - 1): if aa != x[i + 1]: a.append([aa, su]) aa = x[i + 1] su = 1 else: su += 1 a.append([aa, su]) return a def jo(x): # listをスペースごとに分ける return " ".join(map(str, x)) def max2(x): # 他のときもどうように作成可能 return max(map(max, x)) def In(x, a): # aがリスト(sorted) k = bs.bisect_left(a, x) if k != len(a) and a[k] == x: return True else: return False def pow_k(x, n): ans = 1 while n: if n % 2: ans *= x x *= x n >>= 1 return ans """ def nibu(x,n,r): ll = 0 rr = r while True: mid = (ll+rr)//2 if rr == mid: return ll if (ここに評価入れる): rr = mid else: ll = mid+1 """ s = input()[:-1] po = 0 for i in range(len(s)): if s[i] == "p": po += 1 print(len(s) // 2 - po)
Statement AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
[{"input": "gpg", "output": "0\n \n\nPlaying the same gesture as the opponent in each turn results in the score of\n0, which is the maximum possible score.\n\n* * *"}, {"input": "ggppgggpgg", "output": "2\n \n\nFor example, consider playing gestures in the following order: Rock, Paper,\nRock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three\nvictories and suffers one defeat, resulting in the score of 2, which is the\nmaximum possible score."}]
Print the AtCoDeer's maximum possible score. * * *
s206603019
Accepted
p03965
The input is given from Standard Input in the following format: s
t = input() tp = t.count("p") ap = len(t) // 2 print(ap - tp)
Statement AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
[{"input": "gpg", "output": "0\n \n\nPlaying the same gesture as the opponent in each turn results in the score of\n0, which is the maximum possible score.\n\n* * *"}, {"input": "ggppgggpgg", "output": "2\n \n\nFor example, consider playing gestures in the following order: Rock, Paper,\nRock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three\nvictories and suffers one defeat, resulting in the score of 2, which is the\nmaximum possible score."}]
Print the AtCoDeer's maximum possible score. * * *
s973909876
Wrong Answer
p03965
The input is given from Standard Input in the following format: s
z = input("") p = z.count("p") print(p - 1)
Statement AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
[{"input": "gpg", "output": "0\n \n\nPlaying the same gesture as the opponent in each turn results in the score of\n0, which is the maximum possible score.\n\n* * *"}, {"input": "ggppgggpgg", "output": "2\n \n\nFor example, consider playing gestures in the following order: Rock, Paper,\nRock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three\nvictories and suffers one defeat, resulting in the score of 2, which is the\nmaximum possible score."}]
Print the AtCoDeer's maximum possible score. * * *
s415073944
Accepted
p03965
The input is given from Standard Input in the following format: s
#!/usr/bin/env python3 import sys # import time # import math # import numpy as np # import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall # import random # random, uniform, randint, randrange, shuffle, sample # import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj # from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj # from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available. # from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from fractions import gcd # for Python 3.4 (previous contest @AtCoder) def main(): mod = 1000000007 # 10^9+7 inf = float("inf") # sys.float_info.max = 1.79...e+308 # inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x) - 1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x) - 1, input().split())) def li(): return list(input()) s = input() n = len(s) par_counter = s.count("p") print(n // 2 - par_counter) if __name__ == "__main__": main()
Statement AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
[{"input": "gpg", "output": "0\n \n\nPlaying the same gesture as the opponent in each turn results in the score of\n0, which is the maximum possible score.\n\n* * *"}, {"input": "ggppgggpgg", "output": "2\n \n\nFor example, consider playing gestures in the following order: Rock, Paper,\nRock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three\nvictories and suffers one defeat, resulting in the score of 2, which is the\nmaximum possible score."}]
Print the AtCoDeer's maximum possible score. * * *
s127703097
Runtime Error
p03965
The input is given from Standard Input in the following format: s
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; const long double PI = (acos(-1)); #define rep(i, x, n) for (int i = x; i < (int)(n); i++) #define sc(x) scanf("%d",&x) #define scll(x) scanf("%lld",&x) int main(){ string s; cin >> s; int n = s.size(), p = 0, g = 0, ans = 0; rep(i, 0, n){ if (s[i]=='p'){ if (p < g) p++; else ans--, g++; }else { if (p < g) ans++, p++; else g++; } } cout << ans << endl; return 0; }
Statement AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
[{"input": "gpg", "output": "0\n \n\nPlaying the same gesture as the opponent in each turn results in the score of\n0, which is the maximum possible score.\n\n* * *"}, {"input": "ggppgggpgg", "output": "2\n \n\nFor example, consider playing gestures in the following order: Rock, Paper,\nRock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three\nvictories and suffers one defeat, resulting in the score of 2, which is the\nmaximum possible score."}]
Print the AtCoDeer's maximum possible score. * * *
s643176015
Runtime Error
p03965
The input is given from Standard Input in the following format: s
#include<bits/stdc++.h> #define MAX_N 100001 #define INF_INT 2147483647 #define INF_LL 9223372036854775807 #define REP(i,n) for(int i=0;i<(int)(n);i++) using namespace std; typedef long long int ll; typedef pair<ll,ll> P; void init(int n); int find(int n); void unite(int x,int y); bool same(int x, int y); ll bpow(ll,ll,ll); typedef vector<int> vec; typedef vector<vec> mat; mat mul(mat &A,mat &B); mat pow(mat A,ll n); int dx[4] = {1,0,0,-1}; int dy[4] = {0,1,-1,0}; const int MOD = 1000000007; int main() { int N,T=0; string S; cin >> S; REP(i,S.size()){ if(i%2 == 1){ if(S[i] == 'g'){ T++; }else continue; }else{ if(S[i] == 'g'){ continue; }else{ T--; } } } cout << T << endl; return 0; }
Statement AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
[{"input": "gpg", "output": "0\n \n\nPlaying the same gesture as the opponent in each turn results in the score of\n0, which is the maximum possible score.\n\n* * *"}, {"input": "ggppgggpgg", "output": "2\n \n\nFor example, consider playing gestures in the following order: Rock, Paper,\nRock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three\nvictories and suffers one defeat, resulting in the score of 2, which is the\nmaximum possible score."}]
Print the AtCoDeer's maximum possible score. * * *
s452722024
Runtime Error
p03965
The input is given from Standard Input in the following format: s
lis = list(input()) cou = 0 ans = 0 for i in range(len(lis)): if lis[i] == "g": if cou > 0: cou -= 1 ans += 1 else: cou += 1 else: if cou > 0: cou -= 1 else: cou += 1 ans -= 1 print(max(0,ans))
Statement AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
[{"input": "gpg", "output": "0\n \n\nPlaying the same gesture as the opponent in each turn results in the score of\n0, which is the maximum possible score.\n\n* * *"}, {"input": "ggppgggpgg", "output": "2\n \n\nFor example, consider playing gestures in the following order: Rock, Paper,\nRock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three\nvictories and suffers one defeat, resulting in the score of 2, which is the\nmaximum possible score."}]
Print the AtCoDeer's maximum possible score. * * *
s538720672
Runtime Error
p03965
The input is given from Standard Input in the following format: s
lis = list(input()) cou = 0 ans = 0 for i in range(len(lis)): if lis[i] == "g": if cou > 0: cou -= 1 ans += 1 else: cou += 1 else: if cou > 0: cou -= 1 else: cou += 1 ans -= 1 print(max(0,ans))
Statement AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
[{"input": "gpg", "output": "0\n \n\nPlaying the same gesture as the opponent in each turn results in the score of\n0, which is the maximum possible score.\n\n* * *"}, {"input": "ggppgggpgg", "output": "2\n \n\nFor example, consider playing gestures in the following order: Rock, Paper,\nRock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three\nvictories and suffers one defeat, resulting in the score of 2, which is the\nmaximum possible score."}]
Print the AtCoDeer's maximum possible score. * * *
s722482242
Runtime Error
p03965
The input is given from Standard Input in the following format: s
s = input() score = 0 for i in range(len(s)): if i % 2 == 0 and s[i] = "p": score -= 1 elif i % 2 != 0 and s[i] = "g": score += 1 print(s)
Statement AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
[{"input": "gpg", "output": "0\n \n\nPlaying the same gesture as the opponent in each turn results in the score of\n0, which is the maximum possible score.\n\n* * *"}, {"input": "ggppgggpgg", "output": "2\n \n\nFor example, consider playing gestures in the following order: Rock, Paper,\nRock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three\nvictories and suffers one defeat, resulting in the score of 2, which is the\nmaximum possible score."}]
Print the AtCoDeer's maximum possible score. * * *
s193535120
Runtime Error
p03965
The input is given from Standard Input in the following format: s
s = input() g = 0 p = 0 for i in s: if i = "g": g += 1 if i = "p": p += 1 print((g - p) // 2)
Statement AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
[{"input": "gpg", "output": "0\n \n\nPlaying the same gesture as the opponent in each turn results in the score of\n0, which is the maximum possible score.\n\n* * *"}, {"input": "ggppgggpgg", "output": "2\n \n\nFor example, consider playing gestures in the following order: Rock, Paper,\nRock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three\nvictories and suffers one defeat, resulting in the score of 2, which is the\nmaximum possible score."}]
Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}. * * *
s954579123
Wrong Answer
p02677
Input is given from Standard Input in the following format: A B H M
import numpy as np num = input().split() A = int(num[0]) B = int(num[1]) H = int(num[2]) M = int(num[3]) H1 = 30 * H M1 = 6 * M c = min(360, (max(H1, M1) - min(H1, M1))) C = A**2 + B**2 - 2 * A * B * np.cos(c) print(C**0.25)
Statement Consider an analog clock whose hour and minute hands are A and B centimeters long, respectively. An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively. At 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?
[{"input": "3 4 9 0", "output": "5.00000000000000000000\n \n\nThe two hands will be in the positions shown in the figure below, so the\nanswer is 5 centimeters.\n\n![The clock at <var>9</var>\no'clock](https://img.atcoder.jp/ghi/when_a_nameless_star_falls_into_the_sky.png)\n\n* * *"}, {"input": "3 4 10 40", "output": "4.56425719433005567605\n \n\nThe two hands will be in the positions shown in the figure below. Note that\neach hand always rotates at constant angular velocity.\n\n![The clock at\n<var>10:40</var>](https://img.atcoder.jp/ghi/when_flower_petals_flutter.png)"}]
Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}. * * *
s837925105
Wrong Answer
p02677
Input is given from Standard Input in the following format: A B H M
import math print(math.pi + 1)
Statement Consider an analog clock whose hour and minute hands are A and B centimeters long, respectively. An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively. At 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?
[{"input": "3 4 9 0", "output": "5.00000000000000000000\n \n\nThe two hands will be in the positions shown in the figure below, so the\nanswer is 5 centimeters.\n\n![The clock at <var>9</var>\no'clock](https://img.atcoder.jp/ghi/when_a_nameless_star_falls_into_the_sky.png)\n\n* * *"}, {"input": "3 4 10 40", "output": "4.56425719433005567605\n \n\nThe two hands will be in the positions shown in the figure below. Note that\neach hand always rotates at constant angular velocity.\n\n![The clock at\n<var>10:40</var>](https://img.atcoder.jp/ghi/when_flower_petals_flutter.png)"}]