Wombats
Time limit20sMemory limit256 MB
Given an R by C grid where road segments hold wombat counts that change over time, find the fewest wombats on a southward path from the top row to a given bottom intersection.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Divide and conquer, Segment tree
- Solved
- No attempts yet
Problem
Brisbane has been overrun by wombats, giant mutant versions of the raccoon-like animals native to Australia. Your job is to rescue the people.
Brisbane's roads form a large grid. There are east-west horizontal roads, numbered 0, ..., from north to south. There are north-south vertical roads, numbered 0, ..., from west to east. The following figure shows roads numbered this way.

The wombats are coming from the north, and the people flee south. People can move sideways in either direction, but they can only move vertically toward the south, which is the safe direction.
The intersection of horizontal road and vertical road is written . Wombats may be on the road segment between two intersections, and the number of wombats on a segment can change over time. Your task is to tell a person who arrives at a given intersection on horizontal road 0 (the north edge) how to reach a given intersection on horizontal road (the south edge). The route must meet as few wombats as possible.
First, the grid size and the number of wombats on each road segment are given. Then events follow in order. Each event is one of the following two types.
change: The number of wombats on a road segment changes.escape: A person arrives at a given intersection on horizontal road 0. Find a route that sends this person to a given intersection on horizontal road while meeting the fewest wombats.
These events must be handled with the functions init(), changeH(), changeV(), and escape(), defined as follows.
Constraints
changeis called at most 500 times (changeH()orchangeV()calls).escape()is called at most 200,000 times.- The number of wombats on any segment is always at most 1,000.