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

Автор SuperMo, история, 10 месяцев назад, По-английски

I'm stuck in this problem: https://quera.org/problemset/34090?tab=description

you can use google translation for the statement

For n ≤ 22, I used brute force. For n ≥ 40, I randomly selected two disjoint subsets of size 18, and it worked fine. However, I'm failing the cases where 22 < n < 40.

Here is a code snippet: https://pastecode.io/s/h6rdjqzf

the cases I'm failing have 24 < n < 40 Previously, I tried selecting 18 random elements for set1, then chose elements not in set1 for set2, and filled the rest randomly without repetition.

This also failed — the cases where 24 < n < 40 are particularly tough. It's as if there's only one unique solution, and the problem expects you to find it through randomness.

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

»
10 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +17 Проголосовать: не нравится

I think the following should work:

Firstly, note that if $$$n \geq 30$$$, a solution will exist. This is because among all $$$2^{30}$$$ subsets, by pigeonhole, there will exist two of them whose sum modulo $$$m$$$ is the same. And we can construct an answer by discarding the elements common to both subsets.

Therefore, we can perform a brute force on at most $$$30$$$ elements. The rest of the problem is just a standard meet-in-the-middle: we can partition the elements into two sets $$$A$$$ and $$$B$$$, and brute force at most $$$3^{15}$$$ possibilities for each set. The $$$3$$$ represents the decision to "put element in the first group", "put element in the second group", or "put element in neither group". For each of these possibilities, we can store the value of (sum of first group) — (sum of second group) modulo $$$m$$$, and look for a pair of values with sum $$$0$$$ or $$$m$$$. We just need to be a bit careful to deal with the "all elements get put into neither group" case.

Pretty nice problem imo! I didn't expect an elegant solution upon reading it.