Lv.2dpgrid
Grid Paths Around Puddles
- Memory limit
- 256 MB
- Correctness time limit
- 10000 ms
- Solvers
- 0
Each cell of grid is 0 (free) or 1 (puddle). Moving only right or down from (0, 0) to the bottom-right cell without
stepping on puddles, return the number of paths modulo (0 if the start or end is a puddle).
Examples
| grid | result |
|---|---|
[[0, 0, 0], [0, 1, 0], [0, 0, 0]] | 2 |
[[0, 1], [0, 0]] | 1 |
[[0]] | 1 |
Efficiency
This problem has performance tests. Judge the required time complexity from the input sizes in the constraints.
Function signature
solution(grid: int[][]) → int
Constraints
- ;
grid[i][j]is0or1
Expected complexity
- Time
- O(HW)
- Space
- O(W)
Examples
| grid | Expected |
|---|---|
[[0,0,0],[0,1,0],[0,0,0]] | 2 |
[[0,1],[0,0]] | 1 |
[[0]] | 1 |
Hint
Hint
paths[i][j] = paths[i-1][j] + paths[i][j-1] (0 on puddles), filled row by row; one row of storage is enough. Enumerating
paths recursively takes as long as the number of paths.
Time limits per language
| Language | Efficiency time limit | |
|---|---|---|
| C (GCC, gnu17) | 200 ms | estimated |
| C++ (GCC, gnu++23) | 200 ms | derived |
| Python 3.13 | 1000 ms | derived |
| Java 25 | 1248 ms | derived |
| Kotlin 2.4 (JVM) | 1400 ms | estimated |
| C# 14 (.NET 10) | 1400 ms | estimated |
Test groups
| Group | Weight | Tests | Visibility |
|---|---|---|---|
| sample | 0 | 3 | inputs and outputs |
| correctness | 40 | 8 | verdict only |
| performance | 60 | 4 | verdict only |