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

Автор atcoder_official, история, 3 года назад, По-английски

We will hold freee Programming Contest 2023(AtCoder Beginner Contest 310).

We are looking forward to your participation!

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

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

Looking forward to participating!

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

give your best

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

How to solve D ?

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

In F in the first sample, why is the denominator 18? Shouldn't it be 1 * 7 * 2 * 9 = 126? The probability of the results of the N dice satisfying the condition is 11/18.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

bitmask dp is best dp

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

What does "the doubling technique" mean in the editorial for problem G? I've only found the solution using functional graphs.

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

Can someone explain D?

  • »
    »
    3 года назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +9 Проголосовать: не нравится

    First, go through all $$$2^n$$$ possible subsets of players, calculate if the subset is good and store the results in a separate array (using bitmasks as indicies). This can be easily done in $$$O(2^n \cdot n^2)$$$.

    After that, let $$$dp[i][j]$$$ equal the number of ways to pick $$$i$$$ peaceful teams of the people in $$$j$$$ ($$$j$$$ is a bitmask). The transitions should be pretty simple. If we want to calculate $$$dp[i][j]$$$ for specific $$$i$$$ and $$$j$$$, we can iterate over a bitmask $$$k$$$ representing one of the teams. Since $$$k$$$ is a team of the people in $$$j$$$, $$$k$$$ must be a submask of $$$j$$$ (i.e. $$$j | k = j$$$). If the team represented by $$$k$$$ is good (can be checked from the array calculated in the first part), the rest of the people must form $$$i-1$$$ teams and be from the set $$$j \oplus k$$$. The number of ways to do this is $$$dp[i-1][j \oplus k]$$$ by definition.

    Now, the answer will be $$$dp[t][2^n - 1]$$$, but notice that we've overcounted the answer. The statement doesn't care about the order of the teams, but our method will calculate all orders of adding the same teams as different solutions. Thus, we need to divide the answer by $$$t!$$$.

    There are $$$2^n \cdot t$$$ dp states, and for each state we need to calculate up to $$$2^n$$$ transitions. Thus, the total time complexity of the dp is $$$O(4^n \cdot t)$$$ (or $$$O(3^n \cdot t)$$$ if you know how to directly iterate over submasks). This is slower than the first part, so the total complexity of the solution is $$$O(4^n \cdot t)$$$.

    • »
      »
      »
      3 года назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится 0 Проголосовать: не нравится

      that's exactly what I did , can you tell me please why we can go down with O(3^n * t), because I can see O(4^n * t)

      • »
        »
        »
        »
        3 года назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        Can I see your code first?

        • »
          »
          »
          »
          »
          3 года назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится

          Yes sure: my submission

          • »
            »
            »
            »
            »
            »
            3 года назад, скрыть # ^ |
            Rev. 4  
            Проголосовать: нравится +4 Проголосовать: не нравится

            What you're doing in your recursive dp call is you're iterating over all $$$2^n - 1$$$ possible non-empty bitmasks i and checking if the current bitmask is a submask of bitmask with a loop something like this:

            for (int i = 1; i < (1 << n); i++) {
                // check if i is a submask of bitmask
                ...
            }
            

            This can be replaced by

            for (int i = bitmask; i > 0; i = (i-1) & bitmask) {
                ...
            }
            

            This iterases over all submasks of bitmask in decreasing order, and it doesn't iterate over any i that are not submasks of bitmask.

            Proof:

            Now, we can show that the time complexity of the following code is $$$O(3^n)$$$:

            for (int bitmask = 0; bitmask < (1 << n); bitmask++) {
                for (int i = bitmask; i > 0; i = (i-1) & bitmask) {
                }
            }
            
            Proof:
»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone tell me the approach to solve E?

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

in editorial of problem D

 vector dp(1U << N, vector<unsigned>(T + 1));
    dp.front().front() = 1;
    for(unsigned i{}; i < 1U << N; ++i)
        // brute-force over all possible teams that the remaining player with the minimum integer belongs
        for(unsigned c{i + 1 | i}, j{c}; j < 1U << N; ++j |= c)
            if(possible_team[j ^ i])
                for(unsigned k{}; k < T; ++k)
                    dp[j][k + 1] += dp[i][k];

can someone explain this part ? why we always taking a player with the minimum integer ?

upd: seems the answer is just dp.back().back() there is no division by (t!), is it somewhat related to always taking minimum ?

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Although I didn't solve it before contest ended, I think I could give some explanation.

    Suppose that we have divided players into different teams, and now we are going to find a way to uniquely distinguish each of them, in order to avoid counting the same pattern more than once.

    For each team, we sort the number of players in an increasing order, and choose the minimum one as the "leader", and then sort all teams in an increasing order of leaders. For instance, n=3, and t=2, and we have (2) and (3,1) as two teams. Then, we sort them as (1,3),(2). We can prove that this uniquely determine exactly one way to form teams. Thus, we have the solution as follows.

    First, we choose t leaders in an increasing order, which has C(n, t) ways. Then, we divide the left n-t players into t teams, and must make sure that, within each team, they can't have smaller numbers than leader and they are peaceful, which has (n-t)^t. Total complexity is C(n,t)*(n-t)^t*n.

    You can check my codes if you like https://atcoder.jp/contests/abc310/submissions/43648524