chokudai's blog

By chokudai, history, 3 years ago, In English

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!

  • Vote: I like it
  • +88
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    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 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    A short implementation - Submission

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      How to think of short implementations faster ?

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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 years ago, # |
  Vote: I like it +31 Vote: I do not like it

How to do F?

  • »
    »
    3 years ago, # ^ |
      Vote: I like it -14 Vote: I do not like it

    ++

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +3 Vote: I do not like it
    1. represent inputs by their prime factors
    2. cry... edit: editorial's out, I wasn't nearly as close as I'd guessed
  • »
    »
    3 years ago, # ^ |
      Vote: I like it +15 Vote: I do not like it

    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 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      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 years ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve E?

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +6 Vote: I do not like it

    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 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      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 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    .

  • »
    »
    3 years ago, # ^ |
    Rev. 3   Vote: I like it +3 Vote: I do not like it

    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 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    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 years ago, # |
  Vote: I like it +3 Vote: I do not like it

difficulty gap between C & D is soo high!

»
3 years ago, # |
  Vote: I like it +8 Vote: I do not like it

Wrote some hell on D, E was easier

»
3 years ago, # |
  Vote: I like it +19 Vote: I do not like it

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 years ago, # |
  Vote: I like it +9 Vote: I do not like it

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 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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.