1816
A_Ian_Visits_Mary
Explanation
Ian and Mary are frogs living on a grid (Cartesian coordinate plane) with integer coordinates. Ian starts at point (0,0), and Mary is at point (a, b).
Ian wants to reach Mary in at most two jumps. Ian can only jump from one point with integer coordinates to another point with integer coordinates without landing on any other integer-coordinate point in between.
- Ian can always reach Mary in two jumps.
- The first jump can either be to a point on the same diagonal as Mary's position or to a point with the same x or y coordinate.
- In this solution, Ian jumps to the point (a - 1, 1) if a > 0 or to the point (1, 1) if a = 0. This guarantees that no other integer-coordinate points are on the line segment between the starting point and the first jump point.
- In the second jump, Ian jumps directly to Mary's position (a, b).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
B_Grid_Reconstruction
Explanation
- Start by placing the maximum value (2 * 𝑛) in the top-left cell (1, 1), and the second maximum value (2 * 𝑛 - 1) in the bottom-right cell (2, 𝑛).
- Fill the remaining cells in the first row and the second row using the remaining numbers in descending order while alternating rows.
- If the row has an even number of cells, start filling the row from the second cell, otherwise start from the first cell.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
C_Ian_and_Array_Sorting
Explanation
The main idea of the solution is to iterate through the array, making the difference between consecutive pairs alternate between positive and negative. To do this, we can perform the following algorithm:
- Iterate through the array with a step of 2 (i.e., process every other element).
- For each element, check if it is the last element or the second-last element.
- If it's the last element, the answer is "YES" because we can always make the array non-decreasing by adding or subtracting the same value from every other element.
- If it's the second-last element, the answer is "YES" if the current element is less than or equal to the next element, otherwise, it's "NO".
- If the current element is not the last or second-last element, update the next next element by subtracting the difference between the current element and the next element. This ensures that the difference between consecutive pairs alternates between positive and negative.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|