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

cuom1999's blog

By cuom1999, history, 4 years ago, In English

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 (q \leq 10^6)$$$ information: square $$$(x_i, y_i)$$$ contains $$$a_i \ (a_i \leq 10^9)$$$ stones. Other unlisted 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?

  • Vote: I like it
  • +19
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by cuom1999 (previous revision, new revision, compare).

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by cuom1999 (previous revision, new revision, compare).

»
4 years ago, # |
  Vote: I like it +26 Vote: I do not like it

Isn’t the problem independent on the two dimensions (i.e., spreading elements evenly on all rows/columne)? If so, it gets reduced to 1D version, which can be solved pretty easily using greedy approach.