Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can get 90% of the way there using these principles:</p> <ol> <li><p>If the number of liars in a set is equal to zero, decompose that set into sets of size 1, each with number of liars equal to zero. So <code>1 3 0</code> becomes <code>1 1 0</code> and <code>2 2 0</code> and <code>3 3 0</code>.</p></li> <li><p>If the number of liars in a set is equal to the size of the set, decompose that set into sets of size 1, each with number of liars equal to one. So <code>2 5 4</code> becomes <code>2 2 1</code> and <code>3 3 1</code> and <code>4 4 1</code> and <code>5 5 1</code>.</p></li> <li><p>For any two sets A and B that we have, if A is a subset of B, then remove all of A's elements from B, and subtract the number of liars in A from the number of liars in B.</p></li> </ol> <p>We'll use these principles to solve the longer of your two sample problems. Start by taking the input given, and turning them into sets of indices.</p> <pre><code> 3 4 5 6 7 8 [4] 1 2 3 4 5 6 7 8 9 [6] 1 2 3 4 5 6 7 8 9 10 11 12 13 [9] 5 6 7 8 9 10 11 [5] 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [12] 8 9 10 11 12 13 [5] 4 5 6 7 8 [4] 7 8 9 [2] 10 11 12 13 [3] 7 8 9 10 11 12 13 14 15 16 [7] 14 15 16 17 18 19 [4] </code></pre> <p><code>4 5 6 7 8</code> is a subset of <code>3 4 5 6 7 8</code>, so subtract one from the other.</p> <pre><code> 3 [1] 1 2 3 4 5 6 7 8 9 [6] 1 2 3 4 5 6 7 8 9 10 11 12 13 [9] 5 6 7 8 9 10 11 [5] 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [12] 8 9 10 11 12 13 [5] 4 5 6 7 8 [4] 7 8 9 [2] 10 11 12 13 [3] 7 8 9 10 11 12 13 14 15 16 [7] 14 15 16 17 18 19 [4] </code></pre> <p><code>7 8 9</code>, <code>10 11 12 13</code>, and <code>14 15 16 17 18 19</code> are all subsets of <code>4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19</code>, so subtract them.</p> <pre><code> 3 [1] 1 2 3 4 5 6 7 8 9 [6] 1 2 3 4 5 6 7 8 9 10 11 12 13 [9] 5 6 7 8 9 10 11 [5] 4 5 6 [3] 8 9 10 11 12 13 [5] 4 5 6 7 8 [4] 7 8 9 [2] 10 11 12 13 [3] 7 8 9 10 11 12 13 14 15 16 [7] 14 15 16 17 18 19 [4] </code></pre> <p><code>4 5 6</code> has three liars, so decompose them into individual sets.</p> <pre><code> 3 [1] 4 [1] 5 [1] 6 [1] 1 2 3 4 5 6 7 8 9 [6] 1 2 3 4 5 6 7 8 9 10 11 12 13 [9] 5 6 7 8 9 10 11 [5] 8 9 10 11 12 13 [5] 4 5 6 7 8 [4] 7 8 9 [2] 10 11 12 13 [3] 7 8 9 10 11 12 13 14 15 16 [7] 14 15 16 17 18 19 [4] </code></pre> <p>subtract 3,4,5 and 6 from all the sets that contain them.</p> <pre><code> 3 [1] 4 [1] 5 [1] 6 [1] 1 2 7 8 9 [2] 1 2 7 8 9 10 11 12 13 [5] 7 8 9 10 11 [3] 8 9 10 11 12 13 [5] 7 8 [1] 7 8 9 [2] 10 11 12 13 [3] 7 8 9 10 11 12 13 14 15 16 [7] 14 15 16 17 18 19 [4] </code></pre> <p>subtract <code>7 8</code> from <code>7 8 9</code></p> <pre><code> 3 [1] 4 [1] 5 [1] 6 [1] 9 [1] 1 2 7 8 9 [2] 1 2 7 8 9 10 11 12 13 [5] 7 8 9 10 11 [3] 8 9 10 11 12 13 [5] 7 8 [1] 10 11 12 13 [3] 7 8 9 10 11 12 13 14 15 16 [7] 14 15 16 17 18 19 [4] </code></pre> <p>subtract 9 from all the sets that contains it.</p> <pre><code> 3 [1] 4 [1] 5 [1] 6 [1] 9 [1] 1 2 7 8 [1] 1 2 7 8 10 11 12 13 [4] 7 8 10 11 [2] 8 10 11 12 13 [4] 7 8 [1] 10 11 12 13 [3] 7 8 10 11 12 13 14 15 16 [6] 14 15 16 17 18 19 [4] </code></pre> <p>subtract <code>7 8</code> from any sets that contain both.</p> <pre><code> 3 [1] 4 [1] 5 [1] 6 [1] 9 [1] 1 2 [0] 1 2 10 11 12 13 [3] 10 11 [1] 8 10 11 12 13 [4] 7 8 [1] 10 11 12 13 [3] 10 11 12 13 14 15 16 [5] 14 15 16 17 18 19 [4] </code></pre> <p><code>1 2</code> has 0 liars, so decompose them into individual sets.</p> <pre><code>1 [0] 2 [0] 3 [1] 4 [1] 5 [1] 6 [1] 9 [1] 1 2 10 11 12 13 [3] 10 11 [1] 8 10 11 12 13 [4] 7 8 [1] 10 11 12 13 [3] 10 11 12 13 14 15 16 [5] 14 15 16 17 18 19 [4] </code></pre> <p>subtract 1 and 2 from all other sets that contain them.</p> <pre><code>1 [0] 2 [0] 3 [1] 4 [1] 5 [1] 6 [1] 9 [1] 10 11 [1] 8 10 11 12 13 [4] 7 8 [1] 10 11 12 13 [3] 10 11 12 13 14 15 16 [5] 14 15 16 17 18 19 [4] </code></pre> <p>subtract <code>10 11</code> from any sets that contain both.</p> <pre><code>1 [0] 2 [0] 3 [1] 4 [1] 5 [1] 6 [1] 9 [1] 10 11 [1] 8 12 13 [3] 7 8 [1] 12 13 [2] 12 13 14 15 16 [4] 14 15 16 17 18 19 [4] </code></pre> <p><code>8 12 13</code> has three liars, so decompose them into individual sets, and subtract them from any other sets that contain them.</p> <pre><code>1 [0] 2 [0] 3 [1] 4 [1] 5 [1] 6 [1] 7 [0] 8 [1] 9 [1] 10 11 [1] 12 [1] 13 [1] 14 15 16 [2] 14 15 16 17 18 19 [4] </code></pre> <p>subtract <code>14 15 16</code> from <code>14 15 16 17 18 19</code>.</p> <pre><code>1 [0] 2 [0] 3 [1] 4 [1] 5 [1] 6 [1] 7 [0] 8 [1] 9 [1] 10 11 [1] 12 [1] 13 [1] 14 15 16 [2] 17 18 19 [2] </code></pre> <p>Our resulting sets are all disjoint from one another. If we union them together, like so:</p> <pre><code>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [13] </code></pre> <p>we can see that the number of liars from 1 to 19 is 13.</p> <p>This technique doesn't totally solve the problem in all cases. For example, in the shorter of your two sample inputs, this technique does literally nothing. However, for larger problems it does decompose your sets into more modular forms, which I expect would make brute forcing easier/faster. For instance, in the larger sample, we have decomposed the problem space into exactly two possibilities:</p> <pre><code>1. there are 13 liars among soldiers 1-19, and Soldier 20 is not a liar. 2. there are 13 liars among soldiers 1-19, Soldier 20 is a liar. </code></pre> <p>We can easily evaluate these two cases to determine that the minimum liar count is 13, and the maximum is 14. This is much faster than trying all 2^20 combinations of liars and nonliars.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload