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

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

We will hold AtCoder Beginner Contest 210.

The point values will be 100-200-300-400-500-600.

We are looking forward to your participation!

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

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

Thanks for the wonderful contest! I spent a lot of time on D. Wish I was faster with implementation skills got it in like last 2 minutes phew!

D-idea
Code
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Instead of making 4 cases, just make 2 cases. Lets just fix the point for which 'row' value would be bigger. The code gets a lot more simple with that.

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

    A short implementation - Submission

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

      How to think of short implementations faster ?

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

        Think of some tricks to simulate many cases with some variables which you can pass in some function on basis of which it will change. Don't know to explain it better.

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

How to do F?

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

    ++

  • »
    »
    3 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится
    1. represent inputs by their prime factors
    2. cry... edit: editorial's out, I wasn't nearly as close as I'd guessed
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +15 Проголосовать: не нравится

    We can reduce the problem to one big 2-SAT instance, containing one variable per card denoting which side of it we use (plus some supplementary ones).

    First, we go through every possible divisor $$$d \in [2, MAX]$$$, where $$$MAX = 2 \cdot 10^6$$$, that could divide two numbers on the front side of two cards. For every $$$d$$$, we enumerate all cards $$$C_d$$$ that contain a number divisible by $$$d$$$ on either side. We can to this in $$$\mathcal{O}(MAX \log MAX)$$$ if we save every card containing a number for every number. The total size of all $$$C_d$$$ should be roughly $$$4 \cdot 10^6$$$ if we use the $$$\sqrt[3]{n}$$$ approximation for the number of divisors of some $$$n$$$.

    Now for every $$$d$$$, we check whether there exists a card containing numbers divisible by $$$d$$$ on both sides. If thats the case, we go through we all other cards in $$$C_d$$$ and force them be flipped to the side not divisible by $$$d$$$ using a clause like $$$(x \lor x)$$$ or $$$(\overline{x} \lor \overline{x})$$$ (if there is another card with both sides divisible by $$$d$$$, we can immediately output no).

    If there is no card with both sides divisible by $$$d$$$, we want to allow at most one card in $$$C_d$$$ to be flipped to its divisible-by-$$$d$$$ side. For that there is a construction using about $$$3 \lvert C_d \rvert$$$ clauses and $$$\lvert C_d \rvert$$$ supplementary variables. KACTL's 2-SAT code contains an implementation for it. I've always used it without figuring out why it works, but it probably becomes obvious if you spend some time playing around with it on paper. Solving the 2-SAT instance then just requires the standard algorithm using strongly-connected components.

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

      For the last paragraph, you mentioned I used edges in a kind of prefix and suffix order a little bit similar to this Problem.

      Is there any other nice trick to handle these types of implications? mine implementation was messy.

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

How to solve E?

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

    Make pair of $$$Ai$$$ and $$$Cost$$$. Sort on Cost in ascending order, if cost is same compare gcd($$$Ai$$$,$$$N$$$). Calculate final answer by iterating on the vector pair and adding maximum possible edges with the current cost (edges = $$$N$$$ — $$$gcd(N-Ai)$$$). Update $$$N$$$ = $$$gcd$$$ after every iteration. If we reach $$$n$$$ = 1, i.e we made N-1 edges, break.

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

      Actually this explanation is very helpful. I should just draw out some simple examples I guess to understand it. I've never seen any problems like it. What kind of prerequisite is helpful to get this one? The editorial just left me in the dust. I know modular arithmetic for the most part, but don't know how gcd came into it.

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

My code for D was failing for only 3 testcases for some reason. Can someone tell what is wrong with my code? Submission Link

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

    .

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

    Try this case

    2 2 1
    13 1
    1 13
    

    The answer should be $$$4$$$. $$$(1, 2)$$$ and $$$(2, 1)$$$

    I also made the same mistake, you can correct it by rotating the grid clockwise once and repeating the dp.

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

    I made the same mistake 5 times :(

    We are only checking for (i, j) and (i', j'), such that (i, j) is up and left when compared to (i', j'). There need to be two DP checks for both directions.

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

difficulty gap between C & D is soo high!

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

Wrote some hell on D, E was easier

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

A different idea to solve D: Let's solve it as a shortest paths problem. The graph will have a start vertex, which is connected to some randomly chosen tiles in the grid. The rest of the tiles is connected to the end vertex. Then search for the shortest path from start vertex to end vertex.

More concretely, from the start vertex make an edge of length $$$A_{i,j}$$$ to some pairs $$$(i, j)$$$ and from some pairs $$$(i', j')$$$ have an edge of length $$$A_{i',j'}$$$ to the end vertex. Also connect each $$$(i, j)$$$ to neighboring tiles ($$$(i + 1, j), (i - 1, j), (i, j+1), (i, j-1)$$$) with length $$$C$$$.

We set the probability of being connected to the start vertex as 0.5. The probability that the optimal pair has one vertex connected to the start and the other to the end is also 0.5. So if we repeat this whole algorithm $$$k$$$ times, the probability that we missed the optimal pair is just $$$2^{-k}$$$. Admitedly, this has a worse complexity than the solution in the editorial, $$$O(WH * log(WH) * k)$$$

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

Can someone explain problem E solution. I am not able to understand how they are calculating the number of connected components after each operation in the editorial.

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

Can anybody take a look at my code!? This is a O(H * W * log(H + W)) solution, but getting TLE on few cases. Is there a way to make it more efficient?

Here's my Code.