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

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

We will hold AtCoder Beginner Contest 350.

We are looking forward to your participation!

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

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

GLHF!

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

Best point values i have ever seen!!!

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

How to do D?

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

    a very easy approach other than DSU. first thing to observe is that in every connected component, every node will be friend to every other node. this leads us to the conclusion that every connected component should be a complete graph. in a complete graph, the number of edges is given as:

    $$$ M = \frac{n(n - 1)} {2} $$$

    Now the problem is reduced to something very easy. For each connected component, find the number of nodes it has. this will gives us the required number of edges per connected component. After that you can either subtract m at the end or separately count the number of edges in every connected component and subtract it from the number of edges in a complete graph.

    My Submission: Link

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

    I checked evima editorial on yt, it was DFS

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

wtf this tasks

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

Loved E

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

Is G just small to large merging?

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

For question D, I tried to do it with DSU but failed 16 cases don't know why.

My implementation was like:

long long find_parent(ll u,vector&parent) {

if(u == parent[u]) {
    return parent[u];
}
return parent[u] = find_parent(parent[u],parent);

}

// For union

void union_set(ll u,ll v,ll parentU,ll parentV,vector&parent,vector&ranks,ll &ans) {

ll ru = ranks[parentU];
ll rv = ranks[parentV];
if(ru<rv) {
    swap(parentU,parentV);
    swap(rv,ru);
}
ans = ans + (ru-1)*rv + rv-1;
parent[parentV] = parentU;
ranks[parentU] += ranks[parentV];

}

Any idea what wrong I did?

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

How to solve A and B for just 47 seconds? I could not even open the tasks for that time :)

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

how to solve $$$E$$$?

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

    Just DP/memoization, the only problem is with dice roll possibly giving you a 1, but that just multiplies the expected number of moves when choosing to roll a die by $$$\frac{6}{5}$$$.

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

      I thought that this solution would get TLE so I didn't implement it.

      How can we prove that the states number is small enough?

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

        As written in Japanese editorial, any state to consider can be expressed in a form $$$\lfloor N / (2^p 3^q 5^r) \rfloor$$$, where $$$p, q, r$$$ are non-negative integers, since $$$\lfloor \lfloor N / x \rfloor / y \rfloor = \lfloor N / xy \rfloor$$$. Each of $$$p, q, r$$$ have only $$$O(\log N)$$$ possibilities, so in total the number of states is $$$O(\log^3 N)$$$.

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

    DP calculating cost to reach 0 from current number. Min of 2 ways:

    paying X yen for first way

    X + f(num // A)

    paying Y yet to throw the dice

    (6 * Y + f(x // 2) + f(x // 3) + f(x // 4) + f(x // 5) + f(x // 6)) / 5

    You get this from

    f(x) = Y + (f(x // 1) + f(x // 2) + f(x // 3) + f(x // 4) + f(x // 5) + f(x // 6)) / 6

    To get rid of the infinite recursion, move all f(x)'s to the left

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

      The last equation should be —

      f(x) = Y + (f(x // 1) + f(x // 2) + f(x // 3) + f(x // 4) + f(x // 5) + f(x // 6)) / 6

      Instead of,

      f(x) = (Y + f(x // 1) + f(x // 2) + f(x // 3) + f(x // 4) + f(x // 5) + f(x // 6)) / 6

      To arrive at the equation —

      f(x) = (6 * Y + f(x // 2) + f(x // 3) + f(x // 4) + f(x // 5) + f(x // 6)) / 5

      P.S. — You have put Y in bracket and divided by 6 in the last equation.

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

        can you please elaborate more ?

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

          Let F(x) be the cost of reducing x to 0. When rolling a dice, we will pay Y cost. The dice on rolling will give either — 1,2,3,4,5 or 6

          If it is 1, the cost will be F(x) = Y+F(x/1)
          If it is 2, the cost will be F(x) = Y+F(x/2)
          If it is 3, the cost will be F(x) = Y+F(x/3)
          If it is 4, the cost will be F(x) = Y+F(x/5)
          If it is 5, the cost will be F(5) = Y+F(x/5)
          If it is 6, the cost will be F(x) = Y+F(x/6)

          But, we need to find expectation value of F(x), which is essentially the mean. Hence,

          F(x) = (6*Y+F(x/1)+F(x/2)+F(x/3)+F(x/4)+F(x/5)+F(x/6))/6
          F(x) = Y+(F(x/1)+F(x/2)+F(x/3)+F(x/4)+F(x/5)+F(x/6))/6

          Note, that there is a F(x) term on both LHS and RHS (This is because F(x/1)=F(x),as dividing x by 1, will give x)

          Move the F(x) in the RHS to the LHS side, we get —

          F(x)-F(x)/6 = Y+(F(x/2)+F(x/3)+F(x/4)+F(x/5)+F(x/6))/6
          Thus, 5*F(x)/6 = Y+(F(x/2)+F(x/3)+F(x/4)+F(x/5)+F(x/6))/6
          Hence, F(x) = (6*Y+F(x/2)+F(x/3)+F(x/4)+F(x/5)+F(x/6))/5

          Now, this can be solved using Recursion+Memoization. My Submission

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

            Thank you, Even I'm doubtful initially about cancelling out $$$f(\left\lfloor \frac{N}{1}\right\rfloor)$$$ but later saw your comment and felt good that I'm on track.

            In the editorial, it was

            $$$f(N) = Y + \frac{1}{5} f(\left\lfloor \frac{N}{2} \right\rfloor) + \frac{1}{5} f(\left\lfloor \frac{N}{3} \right\rfloor) + \frac{1}{5} f(\left\lfloor \frac{N}{4}\right\rfloor ) + \frac{1}{5} f(\left\lfloor \frac{N}{5}\right\rfloor) + \frac{1}{5} f(\left\lfloor\frac{N}{6}\right\rfloor)$$$

            $$$ f(N) = Y + \frac{1}{6} f(\left\lfloor \frac{N}{1} \right\rfloor) + \frac{1}{6} f(\left\lfloor \frac{N}{2} \right\rfloor) + \frac{1}{6} f(\left\lfloor \frac{N}{3}\right\rfloor ) + \frac{1}{6} f(\left\lfloor \frac{N}{4}\right\rfloor) + \frac{1}{6} f(\left\lfloor\frac{N}{5}\right\rfloor) + \frac{1}{6} f(\left\lfloor \frac{N}{6} \right \rfloor)$$$

            Although it appears recursive due to $$$f(N)$$$ appearing on the right side, by shifting to the left and multiplying the entire equation by $$$\frac{6}{5}$$$, we get:

            $$$ f(N) = \frac{6}{5}Y + \frac{1}{5} f(\left\lfloor \frac{N}{2} \right\rfloor) + \frac{1}{5} f(\left\lfloor \frac{N}{3}\right\rfloor ) + \frac{1}{5} f(\left\lfloor \frac{N}{4}\right\rfloor) + \frac{1}{5} f(\left\lfloor\frac{N}{5}\right\rfloor) + \frac{1}{5} f(\left\lfloor \frac{N}{6} \right \rfloor)$$$

            Final Problem

            $$$f(N) = \min⁡\left(X + f\left(\left\lfloor\frac{N}{A}\right\rfloor\right), \frac{6}{5} Y + \frac{1}{5} f\left(\left\lfloor\frac{N}{2}\right\rfloor\right) + \frac{1}{5} f\left(\left\lfloor\frac{N}{3}\right\rfloor\right) + \frac{1}{5} f\left(\left\lfloor\frac{N}{4}\right\rfloor\right) + \frac{1}{5} f\left(\left\lfloor\frac{N}{5}\right\rfloor\right) +\frac{1}{5} f\left(\left\lfloor\frac{N}{6}\right\rfloor\right)\right)$$$

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

      but what if die is always roll to 1? Problem seems kinda incorrect to me

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

Since some people are not impressed with the problems, I'd like to counterbalance and say that I quite enjoyed this round.

In particular I don't think the tasks being doable and their difficulty curve being smooth is a bad thing for a contest like this, what with it having 'Beginner' in the name and all. :)

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

Solved Problem F by using __gnu_cxx::rope<char> for performing the fast reverse operations (solution) in 1041 ms and Problem G in $$$O(N \times Q \times \log{(N)})$$$ with sorted vectors and binary search in them (solution) in 2764 ms.

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

Any help with why my code in problem G is wrong?

Code

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

Is it possible to get banned in Atcoder?

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

Can anyone tell me why this solution for problem F is giving rte?

Edit: Got AC had some issue in my treap implementation.

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

Actually, the brute force solution to problem G is correct. For instance, in order to make the brute force solution run most slowly, we can use the following graph and query $$$2\ 1\ n$$$ every time:

However, the maximum number of queries is $$$10^5$$$, so the best solution (to make the brute force solution run most slowly) is to use $$$50000$$$ queries to build the graph I mentioned, and use the remaining $$$50000$$$ to query $$$2\ 1\ n$$$. We can calculate that the brute force solution will run $$$50000\times 25000=1.25\times 10^9$$$ times at most $$$^{[1]}$$$. With a 3s time limit, brute force can pass easily.

$$$^{[1]}$$$: If we use $$$n$$$ queries to build the graph, and use the remaining $$$100000-n$$$ to query $$$2\ 1\ n$$$, the brute force solution will run for $$$\dfrac{n}{2}\times (100000-n)$$$ times. Obviously, this is a quadratic function with a maximum value of $$$1.25\times 10^9$$$.

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

Hello, I don't understand the solution for Atcoder : is it a small in large merge ?

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

How to solve F using a stack?

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

    solve it as balanced parenthesis. Reverse the segments with treap or splay tree and for lower-upper cases use scaline to count no of times an index is affected if it's odd change the case.

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

      I'll just say that your solution is a complete overkill. No need for any of that. Just store all the opening/closing intervals and try to come up with a recursive function that prints the interval [l,r], provided s[l]=='(' and s[r]==')'. It works in O(N).

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

        I didn't get you, how will you reverse the respective segments without them??

        It's obvious that we takes intervals [l, r] with given conditions same as we do in balanced parenthesis with the help of stack.

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

          Here's a link to my submission. Url

          The trick is that you don't actually have to perform these operations. You just need to know the "depth" of a parentheses meaning the number of open parentheses that come before it that are not yet closed.

          The idea is very similar to the problem of reverals of word order in a string. For example "this is good" reversed os "good is this". This can be achieved by first reversing each word and then the whole string:

          "this is good" -> "siht si doog" -> "good is this"

          If you can find an efficient way to solve this problem in one pass each depth of parentheses define words of the new "sentence".

          Hope this helps. It's a bit hard to explain, but essentially you only care about whether you print the interval from left to right or right to left.

      • »
        »
        »
        »
        2 года назад, скрыть # ^ |
        ← Rev. 3  
        Проголосовать: нравится 0 Проголосовать: не нравится
        My Recursive solution gives TLE
        Iterative passes. Though it is harder to come up with this iterative approach compared to the recursive one.
»
2 года назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

Will the testcases of A update after ABC350?

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

In problem G, the inputs seem to be generated randomly, how come they guarantee that for type 1 queries u, v belong to different connected components

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

For Sample 3 in C,I think it's OK to print

2

2 3

1 2

But why was it false in judge?(AC*2 & WA*1)

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

I solved ABCD,I am very weak...