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

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

We will hold AtCoder Beginner Contest 182.

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

We are looking forward to your participation!

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

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

Six hours left =.=

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

yay ! I am on a binge solving At Coders problems. They are really cut-the-shit and ad hoc awesome xD !!

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

4 wa in problem C.Know why getting WA but still can't fix that.That's how every contest made my day

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

Tried to fix a runtime error on E for an hour QAQ
Does anyone know any compilation flags that will be helpful in detecting out of bounds error?

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

How to solve F ??

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

How to solve F plss

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

    hint: Transform the problem to finding the number of (y — X) instead of y.

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

    First of all notice that any number $$$X$$$ has unique minimal representation. This can be proved by greedy exchange (using the fact that each successive number is a multiple of the previous number).

    Now, notice the isomorphism (structure equivalence) between the number bases and the (minimal) representation of each number in the system of Yens. There are two properties which are maintained:

    1) If highest bit of $$$A$$$ is greater than $$$B$$$ in our Yen-system, then $$$A \gt B$$$.

    2) Each number has unique representation.

    So we can think of an equivalent problem: given a number $$$X$$$, how many numbers $$$b$$$ there are such that $$$X+b=a$$$ and $$$a$$$ and $$$b$$$ have no bit in common?

    This can be solved, after some thinking, with DP.

    Array g[] represents the representation of $$$X$$$ in Yen-system

    We introduce the concept of "span". span[j] represents the number of elements after the $$$j^{th}$$$ bits of X which have maxed out values of their bit. Then if g[j]>0, we can use this bit in the number $$$b$$$ such that DUE TO the process of carry-over, we don't have this bit in $$$a$$$. You can see the details of dp transition in my Beautiful AC Code

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

      Can you explain the concept of Span a bit more. I couldn't get it. By the way your approach seems better than those of others to comprehend .

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

        the "span" array is the count of consecutive elements whose bit is "maxed out" in $$$X$$$.

        For example, consider a representation where $$$A_{i}=3A_{i-1}$$$ FOR ALL $$$i$$$. This is exactly similar to base-3 representation, and every bit can have atmost $$$2$$$ as coefficient. When a bit in X has 2 as its coefficient, I say that it is "maxed out".

        So lets say the yen-array in given input is

        1 3 9 27 81 243

        and $$$X=271$$$ so that it is $$$222001$$$ in our yen system. Now $$$dp[j]$$$ denotes the number of ways in which we can have $$$b$$$ (in the equation $$$X+b=a$$$) such that $$$b$$$ has no bits in common with $$$a$$$ and only bits from index $$$j$$$ to $$$n$$$ is possibly ON in $$$b$$$. That is every bit from $$$1$$$ to $$$j-1$$$ is definitely $$$0$$$.

        Now ,for example, if we want to have the $$$2^{nd}$$$ bit ON in $$$b$$$, and all before that OFF, we must have that bit equal to $$$1$$$, because BY THE PROCESS OF CARRY OVER, that bit will be OFF in $$$a$$$. And now, notice that carry over makes $$$3^{rd}$$$ bit $$$0$$$ in $$$a$$$. So the span of the $$$2^{nd}$$$ bit is 1, since now we can't have any bit as upto after span bits after $$$j$$$ as ON in $$$b$$$, because then there can't be a carry over.

        After that it is simple DP transition.

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

      Nice explanation! Can you suggest some more problems like this?

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

    I just came out this solution, not pretty sure that it is correct. However it does get me AC.

    The problem is same as "Find the number of integer $$$r$$$ with length $$$N$$$ (leading 0 is allowed) in base $$$A$$$ that shares no common digit with $$$X + r$$$, i.e., $$$\forall_{0 \le i \lt N}, r_i = 0 \lor (X + r)_i = 0$$$".

    Let $$$c$$$ be carry, $$$y = X + r$$$, we have ($$$N$$$ = 4):

    $$$ \begin{array}{r} &c_3 &c_2 &c_1 &0 \\ &x_3 &x_2 &x_1 &x_0 \\ +\quad &r_3 &r_2 &r_1 &r_0 \\ \hline &y_3 &y_2 &y_1 &y_0 \end{array} $$$

    In particular, all digits $$$i$$$ satisfy ($$$m_i = A_{i + 1}/A_i$$$ is the limit of digit $$$i$$$):

    $$$ y_i = (c_i + x_i + r_i) \pmod {m_i} \\ c_{i + 1} = \lfloor \frac{c_i + x_i + r_i}{m_i} \rfloor $$$

    Let $$$dp[i, c]$$$ = the number of valid ways to fill digits $$$[0, i)$$$ while $$$c_i = c$$$. This dp is computed from lower digit to higher digit due to carry-over.

    By iterating all possible values ($$$0 \le r_i \lt m_i)$$$ of $$$r_i$$$, we can get an correct state transition, but it will get TLE. Key observation is that we don't need to iterate all values of $$$r_i$$$. Since $$$r_i = 0 \lor y_i = 0$$$, there are only few valid conditions.

    We decompose $$$r_i = 0 \lor y_i = 0$$$ into 3 disjoint conditions:

    1. $$$r_i = 0 \land y_i = 0$$$
    2. $$$r_i = 0 \land y_i \ne 0$$$
    3. $$$r_i \ne 0 \land y_i = 0$$$

    Let's consider when will these conditions be true?

    1. By substituting $$$r_i = 0, y_i = 0$$$ into the formula of digit $$$i$$$, we find that only when $$$(c_i + x_i) = 0 \pmod {m_i}$$$, condition 1 is true. We transfer to $$$dp[i + 1, c_{i+1}]$$$.
    2. Substituting $$$r_i = 0$$$ into formula, we find that only when $$$(c_i + x_i) \ne 0 \pmod {m_i}$$$ will $$$y_i \ne 0$$$ be true. We transfer to $$$dp[i + 1, c_{i+1}]$$$.
    3. Substituting $$$y_i = 0$$$ into formula, we find that only when $$$(c_i + x_i) \ne 0 \pmod {m_i}$$$ will $$$r_i \ne 0$$$ be true. Notice that in this condition, there will be a carryover. We transfer to $$$dp[i + 1, 1]$$$.

    That's all for the dp transition. Here is my submission.

    Chinese version

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

Is there a dp solution for C?

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

Does we have to use dfs in E?

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

    No, just annoying implementation.
    I used prefix and suffix sums on the rows and the columns.

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

      Not sure if this is what you meant, but you can just iterate over each column twice, once up and once down, and then each row twice, once left and once right. If you go over a block, everything after it is dark, and if you go over a bulb, everything after it is lit. So you just copy paste the same for loop like 5 times, change the bounds and you get the answer. Not really annoying implementation

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

    No, just optimize the brute force solution a little bit.

    The brute force solution is, for each bulb, and for each direction, start from the bulb, and go along with this direction until you meet a block, set each grid passed illuminated by the bulbs. And then, iterate all grids, count the number of grids illuminated by the bulbs. The time complexity is $$$O((H + W)N + HW)$$$.

    The brute force solution might get TLE, although I think it's time complexity is good enough to pass.

    While going along with one direction, you can stop not only when you meet a block, but also when you meet a bulb. If you do so, the time complexity will be $$$O(HW)$$$ cause you will pass a grid at most 4 times.

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

    Using this matrix struct with already clock_rotate, you only need to repeat 4 times rotating the matrix every rotation.

    Submission

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

please anyone explain solution for D

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

    Calculate prefix sums on the input. Also calculate the maximum sum you achieve on the input for every $$$0$$$ to $$$i$$$, where i is from 0 to N — 1 (0-based indexing). Then, you can find the maximum coordinate by iterating from 0 to n and adding the maximum sum in range(0, i) to your current coordinate.

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

    Let us define end[i] as coordinate after the end of ith round (let us assume 0-based index) then, end[i] = end[i-1] + prefix[i]
    Now, if your answer is after round i, and before round i+1

    ans = max(end[i], end[i]+prefix[0] , end[i]+prefix[1] , end[i]+prefix[2] ,..)

    ans = max(end[i], end[i]+max(prefix[0],prefix[1],..,prefix[i]))

    sudo code :

    prefix[0] = a[0]
    for i = 1 to n-1
       prefix[i] = prefix[i-1]+a[i]
    end[0] = prefix[0]
    for i = 1 to n-1
       end[i] = end[i-1]+prefix[i]
    
    max_so_far = prefix[0];
    ans = max(0,prefix[0]);
    for i = 1 to n-1
       max_so_far = max(max_so_far , prefix[i]);
       ans = max(ans, end[i-1] + max_so_far);
    
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What's the idea for E? I spent 50 mins on it thinking it was easier than D but I couldn't get it to work on one of the sample tests; probably some implementation errors. D was easier than I thought though. Great contest, thanks!

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

How to solve E. My O((H+W)*N) solution gave TLE.

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

can someone explain sample test case 2, problem D, how the answer is 2?

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

Problem C and D were easier to do than B for me. Can anyone explain how B should be done?

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

How to solve problem F?

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

How to solve C? People are saying it can be solved using DP. I don't know DP. Can anyone please tell me which variation of DP should actually I learn(as DP is huge) to be able to solve this problem(C)??

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

Can someone tell me what are the 21 solutions to the last sample of problem F, I don't get how there are so many.

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

Can anyone please tell me what's wrong with my code for E: https://pastebin.com/1WPa7pUD ? EDIT: I finally fixed it...I am so stupid!

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

is it possible to see the submission of other participants after the contest at Atcoder.??

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

I recorded a video of me solving the contest: https://youtu.be/VsUvBvgeb9Y. I got 64th, solving all problems in about an hour.

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

Here is my editorial for this contest.

English editorial

中文题解

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

For problem C what am I missing , its WA https://atcoder.jp/contests/abc182/submissions/17965994

Please help!!

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

Here's a screencast of being destroyed by daylight saving time, also includes solutions to all problems