Codeforces and Polygon may be unavailable from December 6, 19:00 (UTC) to December 6, 21:00 (UTC) due to technical maintenance. ×

Minimum steps to spread stones on a grid

Revision en1, by cuom1999, 2020-11-11 22:40:05

Here is an interesting problem for Vietnam Informatics Competition for Youth:

Given a board $$$m \times n \ (m, n \leq 10^6)$$$. You know $$$q$$$ information: square $$$(x, y)$$$ contains $$$a \ (a \leq 10^9)$$$ stones. Other squares contain $$$0$$$ stones. In one step, you could move one stone to an adjacent square, which shares an edge with the current square. The task is to spread stones equally to every square. For example, it takes 2 steps to make [[0, 0], [2, 2]] become [[1, 1], [1, 1]].

I could only model this as a min-cost max-flow problem and solve for small $$$m, n$$$. How to solve the full problem?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English cuom1999 2020-11-12 00:36:35 14 Tiny change: 'ou know $q$ informat' -> 'ou know $q (q \leq 10^6)$ informat'
en3 English cuom1999 2020-11-11 22:41:20 8
en2 English cuom1999 2020-11-11 22:40:46 9 Tiny change: 'es. Other squares c' -> 'es. Other unlisted squares c'
en1 English cuom1999 2020-11-11 22:40:05 638 Initial revision (published)