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

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

We will hold AtCoder Beginner Contest 332.

We are looking forward to your participation!

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

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

Good luck!

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

E is worth 525 points!

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

haha!

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

I hope I can make ABCDE

Good luck for everyone!

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

gl & hf! (though unrated)

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

hope you guys get uogrades and good luck ! :)

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

glhf!

»
5 месяцев назад, # |
  Проголосовать: нравится -8 Проголосовать: не нравится

Can indians participate in Atcoder contests?

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

Good luck for all of you!

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

Всем удачи

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

Good luck and have fun!

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

E is worth 525 points and F is worth 550 points,emmm.....

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

good luck bro

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

Good luck!

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

Was it intended, that the main difficulty in problem $$$E$$$ is not to lose precision?

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

Why do i think problems after C is way harder than before?

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

can anybody tell why this backtracking logic for d is not working,

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

    My guess is that when you marked a state as visited and would not visit it again, since you're using DFS, the first time a state is visited may not be the best answer.

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

Looks like yet another segtree problem F.

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

imho best ABC contest in a long time, the idea for EF more educational than the usual easy problems, thanks a lot :)

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

Can anyone tell why this submission is getting WA? The logic should be correct after all.

Submission link

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

    What's your logic?

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

      Before and after any swap, the elements on the same row or the same column are preserved. So the task is precisely finding minimum number of swaps to equalize row-wise elements and column-wise elements, which then reduces to counting inversions on each axis.

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

How to avoid precision problem in E, I spent all my time to implement it but still get WA. :(

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

On problem E, what makes

cout << (dp.back() * m - sum.back() * sum.back()) / m / m << "\n";

correct while

cout << dp.back() / m - sum.back() * sum.back() / m / m << "\n";

is wrong?

Submission link: AC, WA

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

can anyone help me understand the problem D , i didn't got any clue regarding how to solve that , during the contest

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

Can anybody pls tell me .. in which test case my D fails- Submission — https://atcoder.jp/contests/abc332/submissions/48405276

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

    Comparing two rows or columns using set will ignore the number and order of occurrences of each value.

    You can try this 3 3 1 1 2 1 1 2 2 2 1 2 1 1 1 2 1 2 1 2 the answer should be -1.

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

Again :(

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

Wrong on three cases on problem F. Can someone find an error?

Submission

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

In problem E, I believe my implementation has issues.I would like to understand where I made a mistake.

my code with memoization updated code

still showing WA on 6 testcases :(

»
5 месяцев назад, # |
Rev. 2   Проголосовать: нравится +10 Проголосовать: не нравится

What is the purpose of problem E?

If I use this

long double ans=(long double)((__int128)D*dp[(1<<n)-1][D]-ave*ave)/(D*D);

That's OK.

But this

long double ans=(long double)dp[(1<<n)-1][D]/D-(long double)ave*ave/(D*D);

is wrong.

I know precision is important but this is too ...

»
5 месяцев назад, # |
Rev. 2   Проголосовать: нравится +10 Проголосовать: не нравится

Problem E, I don't understand why the program that uses fewer double get 5 WAs but the program that uses more double get AC?

In the first program, because:

$$$ \begin{aligned} &\frac{1}{D}\sum_{i=1}^{D}\left(x_{i} - \bar x\right)^2 \\ = &\frac{1}{D}\sum_{i=1}^{D} x_{i}^2 + \bar x^2 - \frac{1}{D}\sum_{i=1}^{D} 2x_{i}\bar x \\ = &\color{red}{\frac{1}{D}\sum_{i=1}^{D} x_{i}^2} + \color{blue}{\bar x^2 - \frac{2 \bar x}{D}\sum_{i=1}^{N} w_{i}} \\ \end{aligned} $$$

I use a dp to calculate the minimal value of the red part. As all the x are integer, and I can avoid using double in dp, I believe it will be more precise. The second problem simply sums $$$\left(x_{i} - \bar x\right)^2$$$ and uses long double in dp. Why the second program AC but the first not?

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

    The two lines

    auto xbar = (long double)s[all] / d;
    long double ans = (f[all] + xbar * xbar * d - 2 * sa * xbar) / d;
    

    lost even more precision than dp with double. ($$$5$$$ double multiplications' precision loss in the worst case)

    Try to change the code to

    long double ans = (long double)1.0 * (d * f[all] - s[all] * s[all]) / (d * d);
    

    It will pass :)

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

      Thanks!

      I get it now. The first program uses a value many times larger than the answer, and the larger the value, the worse the precision. But in the second program, the value used in dp is always smaller than the answer, so there doesn't seem to be much precision lost.

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

why E not output "variance * D * D" as the answer? just to edu us how to "avoid precision problem"?

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

std:1224489579591846.408203

wolframalpha:1224489579591846.408163

So why does the question ask for an accuracy of 1e-6?

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

    In this case, you need to calculate relative difference, not absolute difference.

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

Sorry, but my simple brute force (just do dfs) passed E... Submission.

Can anyone hack it?

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

In problem D. How the number of operations required to obtain a desired sequence A(A1, A2, ... , An) starting from the sequence (1, 2 .... N) by repeatedly swapping adjacent two elements is given as the inversion number of the permutation A. Can anyone explain that!?

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

Hi hope you are well!

Could you please check my submissions for problem E, submissions 48412388 and 48412226 should give the same answer mathematically. It does seem like this problem would be better if it requires an output in p/q format rather (maybe mod 1e9+7 or something) rather than output as a fixed point number. Thanks!

Regards Yuhao

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

Where I can found vedio solutions of today's atcoder contest?

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

In problem F, how to do the replacement which is mentioned in editorial with lazy segtree.

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

    Based on the editorial, each update that happens on an interval changes each of its values from $$$x$$$ to $$$\alpha x + \beta$$$ for some $$$\alpha,\beta$$$ related to the update.

    Two different updates described by $$$(\alpha_{\ell},\beta_{\ell}),(\alpha_{k},\beta_{k})$$$ can be merge to $$$\left(\alpha_{k}\alpha_{\ell},\alpha_{k}\beta_{\ell}+\beta_{k}\right)$$$ because

    $$$ \alpha_{k}\left( \alpha_{\ell}x+\beta_{\ell} \right) +\beta_{k} = \alpha_{k}\alpha_{\ell}x + \alpha_{k}\beta_{\ell}+\beta_{k}. $$$
    • »
      »
      »
      5 месяцев назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      What is beta hete? What do we need to store and how to do merge /updates

      Can you share a submission link where atcoder library is being used on this problem?

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

        Beta is the part that gets added each query. From the editorial:

        $$$ α = (λ_i-1)/λ_i $$$
        $$$ β = 1/λ_i * X_i $$$

        Here is a submission with the AtCoder library. (not mine)

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

Can anyone suggest any corner cases for this solution. I am confused.Submission Link

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

There's a $$$O(lgN)$$$ solution for problem B:

let $$$x = GCD(G, M)$$$, $$$ G=ax; M=bx $$$, so there's a cycle with $$$2a+2b-1$$$ operations. After each cycle, both bottles become empty again. So first we mod $$$K$$$ with $$$2a+2b-1$$$ to make $$$0\lt K\lt 2a+2b-1$$$.

Because bottles only become both empty after each cycle, so in cycle it must formed like this:

  • operation type 1/2
  • operation type 3

So in each cycle, each operation with odd index is type 1/2 and each operation with even index is type 3.

If we know the total amount of two bottles, we can know how much in each before/after operation type 3:

  • Before operation type 3, mug holds as more water as possible.
  • After operation type 3, glass holds as more water as possible.

Now we should work out total amount of water.

We can see:

  • If total amount less than G, next operation should be type 2(fill water)
  • If total amount greator or equal than G, next operation should be type 1(empty water)

If there's i operations of type 2 and j operations of type 1, we got current water amount is $$$iM-jG$$$ . And we can find out:

$$$ 0\le iM - (k-i)G < G+M \\ 0\le i(G+M)-kG \lt G+M \\ kG \le i(G+M) \lt (k+1)G+M \\ i = \lceil\frac{kG}{G+M}\rceil $$$

So we can do all rest calculate in $$$O(1)$$$, the total time complexity will be $$$O(lg(min(G,M)))$$$ for "GCD" function.

submission link

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

Can anybody explain the second sample in problem C? I think the answer should be 2

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

    participating a contest requires a logo-shirt, which cant be replaced by the plain one. Since all he had at first is a plain shirt, he has to get 3 (logo) for the 3 contest day. Maybe there is some misunderstood, just check the problem statement carefully.(not english speaker but I hope you can understand what i am talking about)

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

The editorial of D is beautiful :)