Блог пользователя beginner_boy

Автор beginner_boy, история, 6 лет назад, По-английски

Hello, someone can explain how to solve this problem from today contest in AtCoder?

  • Проголосовать: нравится
  • +8
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I solved it with 2 greedy algorithms: pair up the numbers from lowest to highest power of 2 and from highest to lowest power of 2. Taking the best answer of these 2 algorithms passes the tests, not sure if it is correct. I have a feeling this isn't correct but can't find a counterexample (I also didn't think too hard about it).

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +47 Проголосовать: не нравится

Here is a solution. The key observation is that if x = maxia[i], then x can be only be paired with one other number: 2k - x, where k is minimal so that 2k > x. This makes a greedy algorithm clear: sort a[0] < ... < a[n - 1]. Now go from the top. When I am processing a[i], if 2k - a[i] is still in the set, I match it. Otherwise, I continue.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится

    I wish I had noticed that during the contest. I spent most the contest trying to get my max flow solution that uses index compression and grouping all terms with the same value into a single node to work. Dinic's is fast enough but I couldn't figure out a good way to represent the case where two terms with the same value get paired with each other. So I passed all the test cases except 1. I need some sort of flow network where there are certain edges which only allow even quantities of flow to pass through.

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +14 Проголосовать: не нравится

      Smells like Integer LP, which is NP complete!

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится +6 Проголосовать: не нравится

        Thanks for pointing that out. Now I know it is probably not a good idea to try to modify max flow algorithms to handle these new types of edges.