Skip to content

Commit

Permalink
Solve The Last Analógimôn in python
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Jul 22, 2024
1 parent 2c21659 commit b91739c
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
16 changes: 16 additions & 0 deletions solutions/beecrowd/2520/2520.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sys

for line in sys.stdin:
n, m = map(int, line.split())
one_x_index, two_x_index, one_y_index, two_y_index = -1, -1, -1, -1
for y_index in range(n):
y = input().strip().split()
for x_index, item in enumerate(y):
if item == '1':
one_x_index = x_index
one_y_index = y_index
if item == '2':
two_x_index = x_index
two_y_index = y_index

print(abs(one_x_index - two_x_index) + abs(one_y_index - two_y_index))
Binary file added solutions/beecrowd/2520/imgs/UOJ_2520.webp
Binary file not shown.
84 changes: 84 additions & 0 deletions solutions/beecrowd/2520/in.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
4 4
2 0 0 0
0 0 0 0
0 0 0 0
0 0 1 0
4 4
2 0 0 0
0 0 0 0
0 0 0 0
0 0 1 0
4 4
2 0 0 0
0 0 0 0
0 0 0 0
0 0 1 0
4 4
2 0 0 0
0 0 0 0
0 0 0 0
0 0 1 0
3 3
2 0 0
1 0 0
0 0 0
3 3
2 0 0
0 0 0
1 0 0
3 3
2 1 0
0 0 0
0 0 0
3 3
2 0 0
0 1 0
0 0 0
3 3
2 0 0
0 0 0
0 1 0
3 3
2 0 1
0 0 0
0 0 0
3 3
2 0 0
0 0 1
0 0 0
3 3
2 0 0
0 0 0
0 0 1
3 3
0 2 0
1 0 0
0 0 0
3 3
0 0 2
0 0 0
1 0 0
3 3
0 1 0
2 0 0
0 0 0
3 3
0 2 0
0 1 0
0 0 0
3 3
0 2 0
0 0 0
0 1 0
3 3
0 0 1
0 2 0
0 0 0
3 3
0 0 0
0 0 1
0 0 2
3 3
0 0 2
0 0 0
0 0 1
20 changes: 20 additions & 0 deletions solutions/beecrowd/2520/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
5
5
5
5
1
2
1
2
3
2
3
4
2
4
2
1
2
2
1
2
37 changes: 37 additions & 0 deletions solutions/beecrowd/2520/problem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
https://judge.beecrowd.com/en/problems/view/2520

# The Last Analógimôn

Analógimôn Go! is a very popular game. During his quest, the player travels
across many cities capturing virtual little monsters called analógimôns. You
just entered a city that contains the very last analógimôn you still don’t have!

The city can be described as a grid with $N$ rows and $M$ columns. You are at a
given position in the city, while the last analógimôn is at another position in
the same city. In one second, you can move (exactly) one position to the north,
to the south, to the west or to the east. Considering that the analógimôn does
not move at all, you task is to determine the minimum amount of time you need to
reach it.

The following figure shows the first sample input, and shows a path that can be
made in 5 seconds. There are other paths that can be used that take the same
amount of time, but there is no path that takes less time than this one.

<center><img src="imgs/UOJ_2520.webp"></center>

## Input

The input contains several test cases. The first line of each test case contains
two integers $N$ and $M (2 \leq N, M \leq 100)$, the number of rows and columns,
respectively. Next $N$ lines contains $M$ integers each, describing the city.
Integer 0 indicates an empty position; integer 1 indicates your position; and
integer 2 indicates the analógimôn’s position. It is guaranteed that there is
exactly one integer 1 and exactly one integer 2 in the test case, and that all
other integers are equal to 0.

The input ends with end-of-file (EOF).

## Output

For each test case, print a line containing the minimum time needed to reach the
last _analógimôn_, in seconds.
1 change: 1 addition & 0 deletions solutions/beecrowd/2520/tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
beginner

0 comments on commit b91739c

Please sign in to comment.