atcoder_official's blog

By atcoder_official, history, 5 weeks ago, In English

We will hold UNIQUE VISION Programming Contest 2024 Christmas (AtCoder Beginner Contest 385).

We are looking forward to your participation!

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

»
5 weeks ago, # |
  Vote: I like it -32 Vote: I do not like it

I`m so happy

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Merry Christmas! Good luck.

»
5 weeks ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Merry Christmas! Last AtCoder contest before Christmas :)

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I'll participate it. JUST 8 MINUTES LATER.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Can the dots that Santa Claus passes by be negative

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

AtCoder try not to make multiple problems with the same theme just bigger constraints challenge: IMPOSSIBLE

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Santa Claus will come in 3 days!

»
5 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Why set the precision of F to 10^-9, even though its solution is real number binary search? It is quite annoying to deal with precision issue.

Edit: the official solution is not real number binary search.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    __float128 works here, although you'll have to limit number of iterations in binary search to avoid TL.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

does solution of $$$F$$$ contain some elements of geometric right angle triangle calculation?Yes or No?

»
5 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

HELP — Can anybody help with this solution of D,it fails 3 testcases for some reason.

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

    Why were you using same map for both x and y coordinates? I made two seperate maps for both in your code and it passed. Link

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks for your help,this is too stupid a mistake.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I guess it's because you are using the same map for both x and y?

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

i gave an absolute brute force solution to the C and it got AC

n=int(input())
arr=IL()
has=defaultdict(list)
for i,j in enumerate(arr):
  has[j].append(i+1)

ans=1
for element in has:
  index=has[element]
  check=set(index)
  if len(index)==1:
    continue
  for i in index:
    for j in range(1,index[-1]-index[0]+1):
      cur=i
      tem=1
      while cur+j in check:
        tem+=1
        cur+=j
      ans=max(ans,tem)
print(ans)
»
5 weeks ago, # |
  Vote: I like it +4 Vote: I do not like it

For problem G. I got this dp

for(int i=1;i<=n-2;i++){
    for(int j=i;j>=1;j--){
        dp[j] += dp[j-1] * i;
    }
}

Which is the coefficients of this polynomial $$$(x+1)(x+2)(x+3)...(x+n)$$$ which is equal the stirling numbers of first kind, but failed to get this is $$$O(n)$$$ or $$$O(n log n)$$$, only thought about an $$$O(n log^2 n)$$$ fft solution but didn't even code it.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I wasted 40min because I wrote 'continue' as 'break'.

:(

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

can someone give solution for 3rd question ? by the way where can we find the solutions of atcoder contest (this was my first atcoder contest ).

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Why doesn't binary search work for F? Is it because the required precision is not achievable under the given constraints for the iterations of the binary search?

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone help as to why my submission for F is failing on 1 test case and I'm unable to decipher what is wrong with it. my submission

»
5 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

For problem F, why do i set the upper bound of binary search 2e18 WA but 1LL<<60 accept??? code 2e18 code 1LL<<60

  • »
    »
    5 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    wait. what !!! . lemme try. I am getting WA for 2e18.

    UPDATE :

    Tried with (1LL<<60) , doesn't work for me.

    Can you please check what's wrong ?

    https://atcoder.jp/contests/abc385/submissions/60996263

  • »
    »
    5 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Can't we just do it in O(n). Just comparing adjacent heights, I didn't pass it though, my submission but someone else did almost the same and it passed all . Can anyone help me out with what is the difference?

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

      you right, we can do it in O ( N ), but why over-complicate things with Monotonic stack and all. When there is easier Binary search available. ??

      Question doesn't demand O ( N ) , it accepts O ( N * log(range ) ) . So, that's why many people opted for BS.

      • »
        »
        »
        »
        5 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Check my submission I did not use any stack just a single loop. Also the other submission used the same logic and passed all the cases.

        • »
          »
          »
          »
          »
          5 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          ohk, I didn't spend much time on O(N) logic process. but you are right, it is doable.

          • »
            »
            »
            »
            »
            »
            5 weeks ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Can you let me know what is wrong with my code, its failing on 1 test case out of 27 and the other one uses the same logic but passes all.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve problem F?

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Binary search.

    First try to fix a point on some height, and see if all the buildings are visible from this point. If all buildings are visible from this point, then. your answer lies in bottom half, otherwise, answer lies on upper half.

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I tried O(n) with single loop check my submission above.

»
5 weeks ago, # |
Rev. 3   Vote: I like it +6 Vote: I do not like it

How can I solve problem F? I use a binary search to find out the answer, but it got wa. I think my precision of my answer has been hacked, but I can't fix it. So can anyone help me?

Sorry for my poor English.

Here is my code.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

D>>F>E

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    What was the approach to solve E, I had no clue

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Why though ? In D, I simply used binary search on every range of coordinates Santa would travel on the two maps is maintained. I just deleted appropriate coordinates just once. Here is the submission.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

The difficulty of F is centred on the consideration of the boundary case, and the precision.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    But we can just do it in O(n) with single loop though

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yep. But what I meant could be this test example:

      2
      1 99999999
      100000000 100000000
      

      For me I got WA with double, but AC with long double. The reason is that the precision of F was set to 10^-9.

»
5 weeks ago, # |
  Vote: I like it +31 Vote: I do not like it

Please don't set such high precision requirements! Is there a difference between 1e-6 and 1e-9? A lot of people find the right solution but can't break the limits of floating-point accuracy. Such a high precision requirement is difficult to meet and does not improve the "mental difficulty" of the problem, so it is meaningless. (Sorry for the bad translation software.)

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Same I got WA on 1 test case with setprecision(12) sadge

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    If you use struct to hold the number as fraction $$$\frac{a}{b}$$$,it will be easy to only output a number like $$$\frac{a}{b}$$$ at the end,so that the precision requirements is not that harsh.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Some body please tell me what is Wrong in this code for question D

»
5 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

I think there are some major issues in Problem $$$F$$$. Kindly check this submission.

We can observe the following:

  1. If the line segment touches the the top of building $$$A$$$ then the top of building $$$B$$$, $$$B$$$ is considered not visible for the initial condition ($$$H = 0$$$), and considered visible elsewhere (notice the 2nd arg in the 2 invocations of the function '$$$can$$$', changing that arg in any of the invocations gives wrong answer).
  2. Changing the binary search upper bound to other limit like $$$1e18L$$$ or $$$2e18L$$$ gives wrong answer. It seems working only with the written limit (which is equivalent to $$$1LL$$$ << $$$60$$$) and some values around it, as if the test cases were hand-crafted on such limit, which is incorrect testing approach.
  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The first one is correct behavior according to the definition in the problem

    From a point P with coordinate x and height h, building i is considered visible if there exists a point Q on building i such that the line segment PQ does not intersect with any other building.

    For the second one, I guess it would work as long as $$$L = 0, R = 2^k$$$ for big enough $$$k$$$? Not sure how to estimate the error but it feel reasonable to have less error when $$$R$$$ is power of $$$2$$$ since computer store everything in binary. I also trapped on this one, guess it's a lesson to learn :P

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      For the $$$1^{st}$$$ point, what if the line touches the top point of some intermediary building first before reaching the final building? The tests show that in this case, whether the final building will be considered visible or not, is different between $$$H=0$$$ and $$$H>0$$$, which is a contradiction. Kindly check the boolean arg 'isEqualVisible' in the submission in my previous comment.

      • »
        »
        »
        »
        5 weeks ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        Let $$$x$$$ be the smallest real number s.t. there are at least two building intersect with the line, then the range of real number to be able to see all building is $$$(x, \infty)$$$. When $$$x \ge 0$$$, output $$$x$$$ is consider correct just because it have arbitrarily small relative error to the correct answer rather than it's visible on $$$x$$$, and when $$$x < 0$$$, $$$0$$$ is visible and the problem ask you to output $$$-1$$$ in such case.

        • »
          »
          »
          »
          »
          5 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          For this part "and for $$$x=0$$$, $$$x$$$ is still invisible and the problem ask you to output $$$−1$$$ in such case", I think you meant we are asked to output $$$-1$$$ if the buildings are visible with $$$x = 0$$$.

          Considering this submission, the only difference between it and the other one is that now I am passing $$$false$$$ at line $$$50$$$. The impact this change will make is that the checking function '$$$can()$$$' will consider a building as invisible if its slope is equal to the slope of the building before it, which is the case we are discussing (this is done with the help of the function $$$eq()$$$, which considers the difference absolute value for more accurate equality between floating point values). We are getting 'Wrong answer' with this. Even if this is due to deep precision aspects, I believe it is very confusing.

          • »
            »
            »
            »
            »
            »
            5 weeks ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Hmm, seems it's indeed weird, not sure why change of that flag would cause such difference

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Oh this is a fun contest,but I think D is kinda complicated so that I waste much time on it

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Why am I getting wrong answer if I use binary search in E problem as if we can see from H height, then we can see from all heights greater than that?

»
4 weeks ago, # |
  Vote: I like it -8 Vote: I do not like it

Problem G is OEIS-able. Why writers do not check it (especially for problems with few input parameters) before preparing the contest?

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Why problem F could be solved with a monotone stack?

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I just did the problem E found it easy and fun !!

// this is code
signed main()
{
    int N;
    cin >> N;

    vector<vector<int> > T(N);
    vector<int> degree(N, 0);

    for (int i = 0; i < N - 1; ++i)
    {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        T[u].push_back(v);
        T[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }

    int result = N;

    for (int u = 0; u < N; ++u)
    {
        int x=degree[u];
        vector<int> k;
        for(int i=0;i<T[u].size();i++)
        {
            k.push_back(degree[T[u][i]]);
        }
        sort(k.begin(),k.end());
        //pvec(k);
        int y;
        for(int i=0;i<k.size();i++)
        {
            y=k[i]-1;
            int z=k.size()-i;
            result=min(result,N-(1+z+z*y));
            //cout<<result<<" ";
        }
        cout<<endl;
    }
    cout << result << endl;
    return 0;
}