Nov 112014

D. Breaking Board

Author: Winardi Kurniawan
Prepared By: Winardi Kurniawan, Felix Halim
(link to problem D)

I didn’t expect this problem to be one of the least solved problem in the contest (along with problem J). This problem was fully prepared by Winardi Kurniawan (the author himself), and Felix Halim who became the tester for this problem. I only discussed the problem (and the solution) a bit with the author.

First, notice that the input board can be very sparse, with 106 x 106 domain, but only ≤ 100 coins. Thus, the first thing you should do is compress the board by removing all empty rows and columns; in other words, only consider rows and columns which has at least one coin. The resulting board should be at most 100 x 100 in size. After compressing the board, the problem (should) become (much) easier, but not that easy. Remember that the goal of board breaking is to divide the board such that each side has a same coin type, swapping the coins if necessary. We can achieve this goal only if the number of coins in one side is equal to the number of coin with of a certain mark (either O or X), thus, it becomes possible to achieve the goal by swapping the coins.

Next, also notice that minimizing the number of needed swaps is equal to minimizing the number of different mark in one side of the board (those different mark will be swapped). Given the small constraint of N, it is possible to solve this problem using dynamic programming.

Let C be the number of coins with ‘O’ mark in the input board. Define the dynamic programming state dp[i][j][C] as the minimum number of coin ‘X’ will be collected when the board is broken from cell (i, j) and C is the remaining number of coins which should be collected from (i, j) until the end of the breaking. Starting from the top-left most corner, we can solve dp[i][j][C] by solving its subproblem: moving right, or moving down. If we move right, then we collect all coins in previous column. If we move down, then we did not collect any coin. Notice that we should precompute the number of coins which will be collected if we move right at (i, j) to fasten up the program. You also need to precompute the number of ‘X’ coins. These precomputation can be done in O(N2).

Notice that in previous paragraph, we tried to collect ‘O’ on the left side of the board (minimizing ‘X’). We should also do the other alternative: collect ‘X’ on the left side. Thus, twice the DP.

Felix Halim commented on this problem that contestant should be careful with the indexes. It’s easy to have an off-by-one error in this problem. If you check the scoreboard, there are no team which solves this problem in their first attempt.

There are 31 submissions have been made for this problem, in which 3 teams managed to get accepted. The first team who solve this problem is BerinGAS (minute 180) from University of Indonesia. The other two are Sylph (Bina Nusantara University) at minute 249 and DELAPAN.3gp (Institut Teknologi Bandung) at minute 279.

  27 Responses to “ACM-ICPC INC 2014”

  1. “One popular approach was by first sorting all the strings and pair each succesive string whenever possible”, kode saya spt itu, hanya saja pasangkan dr yg terpanjang

  2. komen untuk prob J

    β€œOne popular approach was by first sorting all the strings and pair each succesive string whenever possible”, kode saya spt itu, hanya saja pasangkan dr yg terpanjang

    • koreksi, prob G

    • Ngga, kode kamu nggak seperti itu. Approach kamu itu jadi sama dengan approach greedy yang bener (pasangin dari leaves) — string yang paling panjang saat itu pasti leaf.

      Yang dimaksud “pair each succesive string whenever possible” itu comparenya bener-bener cuma sama 1 string di sebelahnya aja (sorted); sedangkan kamu compare dengan yang panjangnya lebih pendek.

  3. a bit curious about problem H. Did you use the real Kawal Pemilu data for judge’s test case? πŸ˜€

  4. nice problem, nice editorial, pretty helpful, thx πŸ™‚

  5. saya penasaran dgn problem yg blm sempat saya kerjakan (dan AC), apakah mungkin akan diupload ke situs online judge ?

    saya dpt ide sederhana utk problem J dgn menelusuri apakah suatu nilai bisa jadi pivot (menjadi ‘L’), setelah itu cek apakah bs dr index tersebut menjadi good segment, jika tidak cetak impossible, kode saya : [[REMOVED]]

    thx koreksinya πŸ˜€

  6. How about ACM-ICPC 2014 Jakarta write up?? Will it be published?

  7. How can I get input data ?

    Thank you for sharing.

    • Ah… I didn’t notice this comment before >.< I'll not share the input data publicly. You can test your solution in some online-judges, e.g., tokilearning or joj. (I think) I have sent the test data to the admin on those sites.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>