Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traducciones en inglés de los problemas #34

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c652cc5
Traducción en inglés del problema
jimena-olr May 14, 2023
62757a9
Fixed /hook_tools/lint.py lints
jimena-olr May 14, 2023
f326c5d
Update en.markdown
jimena-olr May 14, 2023
4b64d7b
Update es.markdown
jimena-olr May 14, 2023
ab05358
Update es.markdown
jimena-olr May 14, 2023
763d2d1
Update es.markdown
jimena-olr May 14, 2023
e50660c
Markdown de la solución en inglés
jimena-olr May 14, 2023
ef5a58f
Fixed /hook_tools/lint.py lints
jimena-olr May 14, 2023
5551a1d
Update en.markdown
jimena-olr May 14, 2023
d77effb
Update en.markdown
jimena-olr May 14, 2023
8902ddb
Update en.markdown
jimena-olr May 14, 2023
6ba3c36
Traducción en inglés del problema
jimena-olr May 14, 2023
078868d
Update es.markdown
jimena-olr May 14, 2023
9d81d3b
Update en.markdown
jimena-olr May 14, 2023
7adf2c5
Solución del problema en inglés
jimena-olr May 14, 2023
8954216
Traducción del problema en inglés
jimena-olr May 14, 2023
89d0d3c
Fixed /hook_tools/lint.py lints
jimena-olr May 14, 2023
262ea37
Update en.markdown
jimena-olr May 14, 2023
625a4fe
Solución del problema en inglés
jimena-olr May 15, 2023
5aa2671
Update en.markdown
jimena-olr May 15, 2023
adfd9d4
Update en.markdown
jimena-olr May 15, 2023
68d1cfd
Traducción en inglés del problema
jimena-olr May 15, 2023
bee435f
Solución del problema en inglés
jimena-olr May 15, 2023
ccb247e
Traducción del problema en inglés
jimena-olr May 16, 2023
3d55cb1
Fixed /hook_tools/lint.py lints
jimena-olr May 16, 2023
2ac48bd
Solución del problema en inglés
jimena-olr May 16, 2023
d3e5002
Traducción en inglés del problema
jimena-olr May 16, 2023
087abca
Update es.markdown
jimena-olr May 16, 2023
cd5063f
Update es.markdown
jimena-olr May 16, 2023
737923d
Solución del problema en inglés
jimena-olr May 16, 2023
aaa568e
Traducción del problema en inglés
jimena-olr May 16, 2023
e3e0ac4
Fixed /hook_tools/lint.py lints
jimena-olr May 16, 2023
5056db8
Solución en inglés del problema
jimena-olr May 16, 2023
a4b62dd
Traducción del problema en inglés
jimena-olr May 16, 2023
abbbd07
Fixed /hook_tools/lint.py lints
jimena-olr May 16, 2023
8ac0333
Solución del problema en inglés
jimena-olr May 16, 2023
4129b3a
Merge branch 'main' into jimena-olr-patch-1
jimena-olr Sep 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions 2023/dia-1/ofmi-2023-arreglando-huerto/solutions/en.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Fixing the garden - Solution

## Subtask 1. (Ordered elements)

The key to this subtask is to see that, given that there is always a solution, $A_i \geq B_i$ is always achieved. For this reason, we can always move from left to right. In other words, we start from the first element of $A$, subtract the necessary to make it equal to the first one of $B$, and pass it on to the right. We do the same with the second element, and so on.

<details><summary>Solution to the subtask 1</summary>

{{sub1.cpp}}

</details>

## Subtask 2.

The first thing we must do starting from this subtask is knowing if it's possible to make both arrays the same. This results in the garden being fixable if and only if the sum of the elements of $A$ is equal to the one of $B$.

A simple demonstration takes us to an algorithm to solve subtask 2. We can execute a first iteration in which we pass all elements of $A$ from left to right, accumulating all the sum of $A$ in the first box. That way, we can run the same algorithm from the past subtask to accommodate all the necessary elements, now from left to right.

<details><summary>Solution to the subtask 2</summary>

{{sub2.cpp}}

</details>

## Subtask 3.

The last algorithm gives us the answer in $2n$ calls. To reduce this number, we can ensure that within each pair of adjacent boxes, we only have one possible movement (either to the left or to the right).

We start with an array of size $n$, looking for the first index $j$ from left to right so that $\sum_{i=0}^{j} A_i \geq \sum_{i=0}^{j} B_i$. Then, what we must do is pass elements from left to right starting from $j$. Once that's done, all elements of $[0, j]$ will be fixed. Then we apply the same algorithm for the remaining subarray ($[j + 1, n]$).

<details><summary>Solution</summary>

{{solution.cpp}}

</details>
8 changes: 4 additions & 4 deletions 2023/dia-1/ofmi-2023-arreglando-huerto/solutions/es.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Subtarea 1. (Elementos ordenados)

La clave de esta subtarea es ver que, dado que siempre hay solución, en todo momento se cumple que $A_i \gte B_i$. Por esta razón, podemos mover siempre de izquierda a derecha. En otras palabras, comenzamos desde el primer elemento de $A$, le quitamos lo necesario para igualarlo al primero de $B$ y lo pasamos a la derecha. Hacemos lo mismo con el segundo elemento, y así sucesivamente.
La clave de esta subtarea es ver que, dado que siempre hay solución, en todo momento se cumple que $A_i \geq B_i$. Por esta razón, podemos mover siempre de izquierda a derecha. En otras palabras, comenzamos desde el primer elemento de $A$, le quitamos lo necesario para igualarlo al primero de $B$ y lo pasamos a la derecha. Hacemos lo mismo con el segundo elemento, y así sucesivamente.

<details><summary>Solución subtarea 1</summary>

Expand All @@ -12,7 +12,7 @@ La clave de esta subtarea es ver que, dado que siempre hay solución, en todo mo

## Subtarea 2.

Lo primero que debemos hacer a partir de esta subtarea es saber si es posible hacer que los dos arreglos sean iguales. Resulta que se se puede arreglar si y solo si la suma de los elementos de $A$ es igual a la de $B$.
Lo primero que debemos hacer a partir de esta subtarea es saber si es posible hacer que los dos arreglos sean iguales. Resulta que se puede arreglar si y solo si la suma de los elementos de $A$ es igual a la de $B$.

Una demostración sencilla nos lleva a un algoritmo para solucionar la subtarea 2. Podemos hacer una iteración primera en donde vamos pasando todos los elementos de $A$ de derecha a izquierda, acumulando toda la suma de $A$ en la primera casilla. Así podemos correr tal cual el algoritmo de la subtarea anterior para ir acomodando los necesarios ahora de izquierda a derecha.

Expand All @@ -24,9 +24,9 @@ Una demostración sencilla nos lleva a un algoritmo para solucionar la subtarea

## Subtarea 3.

El algoritmo anterior nos da la respuesta en ~$2n$ llamadas. Para reducir este número de llamadas podemos hacer que entre cada par de casillas adyacentes solo haya un movimiento (ya sea a la izquierda o a la derecha).
El algoritmo anterior nos da la respuesta en $2n$ llamadas. Para reducir este número de llamadas podemos hacer que entre cada par de casillas adyacentes solo haya un movimiento (ya sea a la izquierda o a la derecha).

Empecemos con un arreglo de tamaño $n$, busquemos de izquierda a derecha el primer índice $j$ tal que $\sum_{i=0}^{j} A_i \gte \sum_{i=0}^{j} B_i$. Entonces, lo que hay que hacer es hacer pasar elementos de derecha a izquierda a partir de $j$. Una vez hecho, todos los elementos de $[0, j]$ estarán bien arreglados. Entonces aplicamos el mismo algoritmo para el subarreglo que quedó (de $[j + 1, n]$).
Empecemos con un arreglo de tamaño $n$, busquemos de izquierda a derecha el primer índice $j$ tal que $\sum_{i=0}^{j} A_i \geq \sum_{i=0}^{j} B_i$. Entonces, lo que hay que hacer es hacer pasar elementos de derecha a izquierda a partir de $j$. Una vez hecho, todos los elementos de $[0, j]$ estarán bien arreglados. Entonces aplicamos el mismo algoritmo para el subarreglo que quedó (de $[j + 1, n]$).

<details><summary>Solución</summary>

Expand Down
131 changes: 131 additions & 0 deletions 2023/dia-1/ofmi-2023-arreglando-huerto/statements/en.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
In your backyard, you have a garden of size $n$ and you want a specific number of items of different vegetables in it. Everything was going great until a vegetarian snake started stealing your vegetables. Now, some sections of the garden have fewer vegetables than they should, and others somehow have more!

You have two arrays of non-negative integers $A$ and $B$ of length $n$, which represent the current state of the garden and the state you want it to be in, respectively. Each element of an array describes how many vegetables there are or should be in that section of the garden.

Given that the sections of the garden are very close to each other, each time you add or take vegetables from a section, you also modify the number of vegetables from an adjacent section. If you decide to subtract $x$ vegetables to any section of the garden $A[i]$, you'll also have to add $x$ vegetables, either to $A[i-1]$ or to $A[i+1]$.

After each operation, the number of vegetables in each section of the garden $A$ must remain non-negative.

The goal is to make $A$ equal to $B$, meaning each element of $A$ must be equal to the element of $B$ in the same position.

# Implementation

You must implement the function `arregla(A, B)` , which must call the function `mueve(indice, cantidad, direccion)` until `A` becomes equal to `B`.

# Your function, `arregla`

`bool arregla(int n, int A[], int B[])`

## Description

Your submission must implement this function. The program evaluator will look for it in your code and call the function with the following parameters:

## Parameters

- `n`, the number of elements on `A` and `B`.
- `A` and `B`, which represent two integer arrays, both with the same number of elements.

Within this function, you must call the given function `mueve(indice, cantidad, direccion)` to subtract `cantidad` from `A[indice]` and add `cantidad` to `A[indice+direccion]` until the elements on `A` are equal to those on `B`.

The program evaluator has its own copies of `A` and `B`, different from the parameters of `A` and `B` that your function received. This means that, if you modify `A` and `B`, the arrays within the evaluator won't change; and when you call `mueve(indice, cantidad, direccion)`, your arrays `A` and `B` won't change either.

## Return

Your function must return a boolean, which represents if it was possible or not to make both arrays the same.

# The program evaluator function, `mueve`

`bool mueve(int indice, int cantidad, int direccion);`

## Description

The program evaluator will provide you with this function. Call it to subtract `cantidad` from `A[indice]` and add `cantidad` to `A[indice+direccion]`

The function returns `true` if `A` is equal to `B` after doing the operation, and `false` if they're different.

You shouldn't implement this function, you should just call it.

Note: Remember that by calling this function, the arrays `A` and `B` that were passed on to you function as parameters aren't modified.

## Parameters

- `indice`: It's the index of the element you're subtracting from. If you send an index smaller to $0$ or bigger than $n - 1$, the function returns `false` and does nothing.

- `cantidad`: It's the number being subtracted from `A[indice]` and added to `A[indice+direccion]`. Consider that `cantidad` can be negative.

- `direccion`: Its value can only be $1$ or $-1$; if you send another value, the function returns `false` and does nothing. `indice+direccion` must be greater than or equal to $0$ and less than or equal to $n - 1$; if this doesn't happen, the function returns `false` and does nothing.

## Return

A boolean that indicates if `A` is equal to `B` after doing the operation.

## Example

||input
Function called
||output
Returned value
||description
Description
||input
arregla(4, [1, 2, 0, 1], [0, 1, 3, 0])
||output

- ||description
This is the initial call to your procedure, `arregla`.
||input
mueve(0, 1, 1)
||output
false
||description
We subtract $1$ from the element $A[0]$ and add $1$ to the element $A[1]$. The new value of $A$ is `[0, 3, 0, 1]`. The function returns `false`because $A$ is not equal to $B$.
||input
mueve(1, 2, 1)
||output
false
||description
We subtract $2$ from the element $A[1]$ and add $2$ to the element $A[2]$. The new value of A is `[0, 1, 2, 1]`. The function returns `false`because $A$ is not equal to $B$.
||input
mueve(3, 1, -1)
||output
true
||description
We subtract $1$ from the element $A[3]$ and add $1$ to the element $A[2]$.
The new value of A is `[0, 1, 3, 0]`.
As $A$ equals $B$, the function returns `true`.
||end

# Limits

- $1 \leq n \leq 10^4$
- $0 \leq A_i, B_i \leq 10^5$

# Subtasks

- **Subtask 1 (18 points):**
- The initial elements of $A$ are in descending order, meaning $A[i] \geq A[i+1]$, and those of $B$ are in ascending order, $B[i] \leq B[i+1]$ for all $i$.
- It is certain that there is always a solution.
- $n \leq 10^4$
- **Subtask 2 (37 points):**
- $n \leq 10^3$
- **Subtask 3 (45 points):**
- $n \leq 10^4$
- Additionally, you must use the smallest number of calls possible to function `mueve`.

# Experimentation

{{libinteractive:download}}

The test evaluator receives the file `sample.in` with the values $n$ on the first line, the array $A$ on the second line and the array $B$ on the third line. For the previous example case, `sample.in` would look the following way:

```
4
1 2 0 1
0 1 3 0
```

_IMPORTANT:_ The test evaluator and the final program evaluator that are used to grade your solution are different. The testing evaluator has the debugging of your solution and can implement some functions differently.

---

![](arreglando.jpeg 'Chasing Nicholas, the vegetarian snake.')
83 changes: 83 additions & 0 deletions 2023/dia-1/ofmi-2023-benito/solutions/en.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Benito the Bunny - Solution

## Subtask 1. ($1 \leq n \leq 3$)

Given that the possible values of $n$ are very small, we can solve these cases by hand. The matrix of size $1\times 1$ is simply 1. While for the one of size $n=3$ it can be one of the following two forms:

```
1 1 1 2 2 2
1 2 1 2 1 2
1 1 1 2 2 2
```

Thus, we can make a code that checks if one of these cases is happening.

<details><summary>Solution to the subtask 1</summary>

{{sub1.cpp}}

</details>

## Subtask 2. (Spiral-shaped matrix)

Being a spiral, we can look for the biggest number in the matrix and print it as an answer. We can also analyze the smaller cases and observe that, given a matrix of size $n$, either growing from the outside to the inside or from the inside to the outside, the answer will be $(n + 1) / 2$.

<details><summary>Solution to the subtask 2</summary>

{{sub2.cpp}}

</details>

## Subtask 3. (Matrices spiraling from the outside to the inside)

Focusing on only one type of spiral allows us to analyze which patterns or structures they must have. For this case, we could run a simulation and build the matrix from the outside to the inside, but even when doing it by hand, we can observe that the number of a box depends on how close it is to a bound of the matrix.

For example, for the $7\times 7$ matrix,

```
1 1 1 1 1 1 1
1 2 2 2 2 2 1
1 2 3 3 3 2 1
1 2 3 4 X 2 1
1 2 3 3 3 2 1
1 2 2 2 2 2 1
1 1 1 1 1 1 1
```

The missing number `X` is at a 5-unit distance from the left bound, a 3-unit distance from the right bound, and a 4-unit distance from the upper and lower bounds. Effectively, the corresponding number of this position is 3.

As homework, you could demonstrate that this will always be fulfilled for the matrices spiraling from the outside to the inside. The important thing is that given a position $(x, y)$, the number that should be present in the $n\times n$ matrix can be calculated with the following function:

```g++
int distancia(int x, int y, int n) {
return std::min(std::min(x + 1, y + 1), std::min(n - x, n - y));
}
```

With a double `for`, we can check if the matrix spirals from the outside to the inside or not.

<details><summary>Solution to the subtask 3</summary>

{{sub3.cpp}}

</details>

## Subtask 4. (Matrices spiraling from the outside to the inside)

For this subtask, was can make the same observations as in subtask 3, but the distance toward the closest bound won't indicate the number of the box. Instead, this value will tell us how much we would need to subtract from $(n + 1) / 2$ to have the correct number on that position.

<details><summary>Solution to the subtask 4</summary>

{{sub4.cpp}}

</details>

## Subtask 5.

We can join the solutions of the last two subtasks to achieve a general solution.

<details><summary>Full solution</summary>

{{solution.cpp}}

</details>
4 changes: 2 additions & 2 deletions 2023/dia-1/ofmi-2023-benito/solutions/es.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Con un doble `for` podemos checar si es una matriz espiral de adentro hacia afue

</details>

## Subtarea 4. (Matrices de afuera hacia adentro)
## Subtarea 4. (Matrices de adentro hacia afuera)

Para esta subtarea podemos hacer las mismas observaciones que en la subtarea 3, solo que la distancia hacia el extremo más cercano no nos indica el número de la casilla, nos indica cuánto habría que restarle a $(n + 1) / 2$ para tener el número correcto de dicha posición.

Expand All @@ -72,7 +72,7 @@ Para esta subtarea podemos hacer las mismas observaciones que en la subtarea 3,

</details>

## Subtarea 5
## Subtarea 5.

Podemos unir las soluciones de las últimas dos subtareas para tener la solución general.

Expand Down
64 changes: 64 additions & 0 deletions 2023/dia-1/ofmi-2023-benito/statements/en.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Benito is the world's most famous bunny due to his successful career as a singer.

After ending his most recent tour _Un saltito sin ti_ , Benito is determined to return to his burrow with the objective of eating the biggest carrot in his garden.

However, fame has taken a toll on him, which is why Benito only eats carrots that have grown in a spiral-shaped garden; if this doesn't happen, Benito turns angry and becomes a bad bunny.

A garden is determined to be spiral-shaped if:

1. It is a square-shaped matrix of $n \times n$ with an odd $n$ value.

2. One of the following conditions is achieved:

- A spiral is formed from the outside to the inside. This means that the outside bounds of the square are formed exclusively by $1$ $mm$ carrots, while the bounds of the square inside it contain $2$ $mm$ carrots, and so on until you get to the interior with the square of $1 \times 1$ with the biggest type of carrot.

- A spiral is formed from the inside to the outside. This means that the outside bounds of the square are of the biggest size possible for this matrix of $n \times n$ and this diminishes slowly until the interior with the square of $1 \times 1$ with a carrot of $1$ $mm$.

![](huertoEspiral.png 'An example of a spiral-shaped garden going from the inside to the outside.')

The program must be capable of identifying if the matrix is a spiral or not.

You must print the size of the biggest carrot there is in Benito's garden.

# Input

In the first line, there is the integer $n$, which represents the size of the matrix.

In each one of the following $n$ lines, there will be $n$ separate integers, which are separated by a space that represents the size of the carrots in millimeters.

# Output

Print the size of the biggest carrot in the spiral-shaped garden.

In case the garden is not spiral-shaped, print -1.

# Examples

||examplefile
sample
||examplefile
sample1
||examplefile
sample2
||end

# Limits

- $1 \leq n \leq 800$. $n$ has an odd value.

# Subtasks

- **Subtask 1 (10 points):**
- $1 \leq n \leq 3$.
- **Subtask 2 (10 points):**
- It is a certainty that matrices are always spiral-shaped.
- **Subtask 3 (20 points):**
- Only matrices that are not spiral-shaped and those in spirals from the outside to the inside.
- **Subtask 4 (20 points):**
- Only matrices that are not spiral-shaped and those in spirals from the inside to the outside.
- **Subtask 5 (40 points):**
- No additional considerations.

---

![](benito.jpeg "Benito, the world's most famous bunny.")
Loading
Loading