CIW '25 P4 - Hit the Griddy

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type
Canadian Informatics Workshop: 2025 Day 2, Problem 1

Ernest has a special dartboard that can be represented as an N \times M grid, where N and M are odd. The rows are numbered from 1 to N, and the columns from 1 to M. For the cell in the i^\text{th} row and j^\text{th} column, we denote its value by v_{i, j}. For this specific grid, v_{i, j} equals the concatenation of i and j. Some examples are v_{12,434} = 12434 and v_{90,10}=9010.

Ernest wants to throw a dart to hit the center of the dartboard. However, the center of this dartboard is defined a bit strangely; instead of the geometric center, it is defined as the cell containing the median value in the grid.

Help Ernest determine what the median value is!

Input Specification

The first and only line of input contains two space-separated integers N and M. It is guaranteed that N and M are odd.

The following table shows how the available 25 marks are distributed:

Marks Awarded Bounds on N Bounds on M
2 marks N = 1 1 \le M \le 10^9
3 marks 1 \le N \le 10 1 \le M \le 10
4 marks 1 \leq N \le 2 \, 000 1 \le M \le 2 \, 000
8 marks 1 \le N \le 100 \, 000 1 \leq M \leq 10^9
8 marks 1 \le N \le 10^9 1 \leq M \leq 10^9

Output Specification

On a single line, output the median value of all values in the grid.

Sample Input 1

3 5

Sample Output 1

23

Explanation for Sample Output 1

The dartboard looks like:

11 12 13 14 15
21 22 23 24 25
31 32 33 34 35

The median value is 23.

Sample Input 2

1023 957

Sample Output 2

453512

Comments

There are no comments at the moment.