chokudai's blog

By chokudai, history, 15 months ago, In English

We will hold AtCoder Beginner Contest 170.

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

We are looking forward to your participation!

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

»
15 months ago, # |
  Vote: I like it -67 Vote: I do not like it

how to explain the first example of problem D?

thanks a lot.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it -65 Vote: I do not like it

    ya same here , someone plz!!

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it +28 Vote: I do not like it

      Not during the contest. Definitely not here. You can request a clarification, maybe the Jury decides to give some further explanation, maybe they don't, but this is the only fair way to get explanation during a contest.

»
15 months ago, # |
  Vote: I like it -17 Vote: I do not like it

omg, My code won't even give an o/p locally but when I submit, it got accepted in Q D. xD

»
15 months ago, # |
  Vote: I like it -11 Vote: I do not like it

How to browse the test data in problem C?

»
15 months ago, # |
  Vote: I like it +3 Vote: I do not like it

How can i see judge test cases after a contest in atcoder ?

»
15 months ago, # |
  Vote: I like it -15 Vote: I do not like it

Find the number of integers i(1≤i≤N) with the following property: input : 4 5 5 5 5 output: 0 how this possible ,,,,bcz the value of i is i<=i<=N ,,, how here i become 0??? plz explain!!!

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    here i is the index number/position and u have to find out total number of such index for which the given condition satisfy(it may be 0 to n(inclusive))

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    they start iteration from 1 not from 0 the first element is A1 and the last is An

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Shit I wasted time at B, thinking by combination they meant both should be there -_-

»
15 months ago, # |
  Vote: I like it +72 Vote: I do not like it

Problem F is the same as this

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

nice contest!!

»
15 months ago, # |
  Vote: I like it +33 Vote: I do not like it

Editorial:

A
B
C
D
E
F
  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    hello, i'm not geeting question 2

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Actually its simple math problem. Let a and b be the number of cranes and turtles respectively, thena + b = X and 2a + 4b = Y, See my Submission

      • »
        »
        »
        »
        15 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        okay got it

      • »
        »
        »
        »
        15 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I made a boolean array for question c and take each element whether it is present or not and then I traverse it and if it is false then res=min(res,i-x); I checked this but this is not giving the answer, why?

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    thank you for editorials!

    i quite didn't get the heuristics you used in problem F: can you please write what happens when you move from dp[x][y] to dp[x + 1][y], how are your sets changing? how can your sets be defined? thanks.

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      When moving from dp[x][y] to dp[x + 1][y] only if dp[x+1][y] hasn't been updated yet,you can use sets to find it.

      Then the cell->[x+1][y] is deleted from the set which represents column y as well as the one represent row x+1.Because [x+1][y] has been updated now!

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

    In problem E multiset can be used instead of segment tree, because u need to know min over all array and can keep all top values in multiset.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    In problem F, I don't understand how are you updating all possible [m][n] for state [i][j] which satisfies all three conditions, I tried it using loop from 1 to K resulting in complexity of O(H*W*K) :(

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I just use set to store all of the states that are not updated yet.

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

For the D problem- Let us sort the array first. Now, let's iterate through the array from the beginning. After that, the idea is to maintain a map that will store all the values that have a)appeared in the array itself b)or are multiples of those elements that have originally appeared so far, that are less than 1e6. Time Complexity-0(N*(log(1e6))), which is equivalent to an O(N) complexity Here's my submission- https://atcoder.jp/contests/abc170/submissions/14321810 Also, for the E problem, do we have to maintain a vector of priority queues?

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +11 Vote: I do not like it

    Priority queue won't be sufficient because we need to delete too from kindergarten. So I used multiset.

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it +11 Vote: I do not like it

      You don't need to delete an element from priority_queue any time some child leaves it. Instead each time you want to find maximum pick the largest element from priority_queue, check if the infant in question has leaved our kindergarden and if so erase it from queue and keep going. This still is amortised $$$O(n log n)$$$ since there are $$$n$$$ insertions and each element will be deleted at most once.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    we can also solve E by multiset(vector of multiset). link: Your text to link here...

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

    what if array is of size 1e6 and a[i]=1 for 0<=i<=n-2 a[i]=200000 for i=n-1

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve F?

  • »
    »
    15 months ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    It's shortest path with the following optimizations:

    1) You never want to go backwards

    2) You never want to try something in the same direction, you could have just computed that before.

    My submission for F

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Wonderful soln. could you just add some comments and send the soln so that I can understand 100%. Mainly what are the first second things and how is the @ thing being checked!
      Thanks a lot secundus

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Are heuristics expected to pass for F?

submission

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Was F bfs but I think time complexity will be more with BFS solution

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

In problem D , i tried to solve by marking all multiples of numbers in array . But it gave TLE . I guess it is O(nlogn) (because it corresponds to harmonic series). submission

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Whats wrong with my code for F? Link

»
15 months ago, # |
  Vote: I like it +15 Vote: I do not like it

I have solved all problems in a contest for the first time. Hurray!!! Here's my idea for F:

Spoiler

My submission: link

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

    Interesting idea. The reason this greedy modification works better than normal bfs is that every cell gets visited at max 4 times in your solution

»
15 months ago, # |
Rev. 2   Vote: I like it +23 Vote: I do not like it

E was a heavy implementation problem?

Upd : WA/RE teaches a lot.

Learned, why should we refactor our code. Make separate functions for the repeated tasks.

AC

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +23 Vote: I do not like it

    :( ,I think it's more like a basic data structure problem.

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I used sorted maps i.e (TreeMap in java ) for everything, maintained sorted lists for everything. But its just failing for 1 tc i.e random_case

      Submission

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

        I must have done many unnecessary things, cause it took me a hell lot of time code this.

      • »
        »
        »
        »
        15 months ago, # ^ |
        Rev. 2   Vote: I like it +9 Vote: I do not like it

        Here are 2 small cases where your submission fails:

        Test 1
        Test 2
»
15 months ago, # |
Rev. 3   Vote: I like it -30 Vote: I do not like it

.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Edit : I changed x*100 to 102 and it got AC right after the contest ended aghhh

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    This is not a way to ask doubt you should not spam discussion with full code just post link of your code and try to explain your logic a little bit.

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

I created lot of treemaps and hashmaps in E and I was shocked that my code worked on the 1st go, the code got unbelievably complex though. In F, the naive BFS solution gave TLE on 2 test cases only. How to solve it efficiently?

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Naive bfs complexity will be O(h*w*K), which will TLE. I have explained my O(h*w*4) solution in this comment.

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

      You did not take sorting into account. It is O(hwlog(hw))

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +11 Vote: I do not like it

    Keep sets for unvisited cells (for each row and for each column), and remove cells when you add them to the queue. Then you would only look at every cell once. This introduces a logarithmic factor, but also removes the dreadful factor of $$$k$$$ in the naive solution.

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

      I solved F using a parent array which marks from where the element came into the bfs queue. Now when processing a nodes child if the node and it's child came from same parents then break the loop. This helps to solve it without the log factor and avoids moving in the same direction again and again. Solution link: https://atcoder.jp/contests/abc170/submissions/14351675

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

How to Solve F ?

»
15 months ago, # |
  Vote: I like it +29 Vote: I do not like it

I learnt after wasting 40 minutes in problem E that, multiset.erase() removes all occurrences of a given value from the multiset. To erase a single element, use this:

multiset<int> s;
s.erase(s.lower_bound(value));
//Make sure value is stored in the multiset!!
  • »
    »
    15 months ago, # ^ |
    Rev. 2   Vote: I like it +4 Vote: I do not like it

    This is why I use map to store number of occurrences and erase the key once no. of occurrences becomes 0.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +16 Vote: I do not like it

    An alternative, if you don't want to worry about whether or not the value is present in the multiset:

    multiset<int> s;
    auto it = s.find(value);
    if(it!=s.end())
       s.erase(it);
    
  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yea I also learned this today in problem D

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    or s.erase(s.find(value));

»
15 months ago, # |
  Vote: I like it -6 Vote: I do not like it

For C binary search also works.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    How ?

    • »
      »
      »
      15 months ago, # ^ |
      Rev. 4   Vote: I like it 0 Vote: I do not like it

      Well first increment iterator and search for the closest next number which isn’t present in the array. Do same by decrementing it.Binary search allow us searching that number faster(within timelimit). link

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

-->For d solution i came up with this solution

-->Created a map for count of given integers,for any number check whether its divisors present in map (or) when its count is >1 function returns false else increment count

-->solution :link

-->it passed 27 test cases and wa for 22 can any one tell what i have missed??? or corner test cases i have missed??

  • »
    »
    15 months ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    Try this test case

    Test case

    the answer should be 0 but your code's output will be 1

    another test case where your code will fail

    Test case

    the answer should be 0 but your code's output will be 1

    Accepted code link

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

https://atcoder.jp/contests/abc170/submissions/14329950 https://atcoder.jp/contests/abc170/submissions/14331317

The first submission for problem D gives me TLE, but when I replaced at line 172, MAXN = 10^6 with the real maximum of the input, second submission got accepted and actually the difference in time is huge. Why is that? It seems really strange to me. I spent too much time on that and I was kinda lucky to come up with that replacement because I was sure that the complexity is sufficient.

Thank you !

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve problem E of todays contest ?

  • »
    »
    15 months ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it

    Maintain a multiset for each kindergarden and one multiset for the maximums of the kindergardens. Now at every query you just need to insert/erase only from three multisets.

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

In problem d I thought checking all the factors will give TLE. but when 10 min was left I thought maybe I should submit the solution with TLE but rather it got accepted.

lesson learned : analysis of time complexity should be done carefully.

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

    O(nlogn) so why tle?

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it +9 Vote: I do not like it

      osthir_brogrammer it's O(n*sqrt(n))

      • »
        »
        »
        »
        15 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I was thinking the same but it's not correct, I think ??

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

      can you explain how ??

      here is my approach: I took the frequency array, when the element was greater than 1 I ignored the element and when it was equal to one I checked all it's factors and checked if any of them were present or not.

      • »
        »
        »
        »
        15 months ago, # ^ |
        Rev. 2   Vote: I like it +1 Vote: I do not like it

        Numen Your approach is correct

      • »
        »
        »
        »
        15 months ago, # ^ |
          Vote: I like it +4 Vote: I do not like it

        you can preprocess divisors of numbers from $$$1$$$ to $$$Max$$$ using this way in $$$O(MaxlogMax)$$$

        vector<int>Div[MAX+2]
        for(int i = 1 ; i < MAX ; ++i)
           for(int j = i ; j < MAX ; j += i)
               Div[j].push_back(i) ;
        

        Div[x] stores divisors of x.

        `

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

          I think now I understand the time complexity :) and this is a nice way to preprocess all the factors.

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Did anyone solve D in O(n * sqrt(n))?

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

    I did

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      can you give the link to the code/submission?

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

        Link

        Useful Code in case if you find hard to read my JAVA template,

        int n=ni();
        HashMap<Integer,Integer> hm = new HashMap<>();
        int[] arr = new int[n];
        for(int i=0;i<n;++i){
            arr[i] = ni();
            //hs.add(arr[i]);
            if(hm.containsKey(arr[i])){
                hm.put(arr[i],hm.get(arr[i])+1);
            }
            else{
                hm.put(arr[i],1);
            }
        }
        int ans = 0;
        for(int i=0;i<n;++i){
            if(hm.get(arr[i])==1){
                boolean pos = false ;
            for(int j=1;j*j<=arr[i];++j){
                if(arr[i]%j==0){
                    if(j*j==arr[i]){
                        if(j==arr[i]) continue ;
                        else{
                            if(hm.containsKey(j)){
                                pos =true ;
                                break ;
                            }
                        }
                    }
                    else{
                        if(j != arr[i]){
                            if(hm.containsKey(j)){
                                pos = true ;
                                break ;
                            }
                        }
                        if(arr[i]/j != arr[i]){
                            if(hm.containsKey(arr[i]/j)){
                                pos = true ;
                                break ;
                            }
                        }
                         
                    }
                }
            }
            if(!pos) ans++;
            }
        }
        pn(ans);
        
      • »
        »
        »
        »
        15 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        You can check out the C++ implementation of the same here! Submission for D

»
15 months ago, # |
  Vote: I like it +9 Vote: I do not like it

Lesson learned from D:

std::unique does not change vector size! must change it by myself.

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

is memory limit exceeded will show as RE at atcoder ? PS. I am getting RE for the only 1tc in problem E i.e random_10, can someone give me some corner cases? But I feel as setter must have added those corner cases in test files,this RE must be because of Memory Limit.

Submission

»
15 months ago, # |
Rev. 2   Vote: I like it +2 Vote: I do not like it

Messed up big tym n now, messing up on atcoder has become a habit :-(

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

Approach for Problem D — create frequency array for all elements and then check for each element whether any of its divisor is present in the array or not

Gives tle in one case and few wrong test cases

Link : https://atcoder.jp/contests/abc170/submissions/14362767

Any Suggestions ?

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I did the opposite, I marked every multiple of each element till $$$ 10^6 $$$ and stored it in an array. Complexity would be like $$$ O(n\ log\ log (10^6) ) $$$

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    WA-some condition is missing TLE-may be using map for finding element complexity -log(n) Ac code-https://atcoder.jp/contests/abc170/submissions/14339476

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    For the TLE part:- Just change your map to array.

    Accepted code link

»
15 months ago, # |
Rev. 5   Vote: I like it +2 Vote: I do not like it

In Problem F, I understand the solution where one can keep a set for every row and column, to prevent visiting a single cell multiple times.

But, after looking at some codes, I realised some solutions broke their loop if dist[cr][cc] + 1 > dist[r][c] where (cr, cc) is the current cell and (r, c) is the cell to be visited, from the current cell.

For, instance checkout this submission.

I understand the correctness of the solution, but I do not understand how this solution will pass the time limits.

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

when will they release the English editorial?

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    In 1-2 days, in the same editorial pdf, there will be an English version in the end.

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

    It's there now

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone explain how the complexity of D is O(N*logN) (or O(N*sqrt(N)) from what I saw in other questions)? Shouldn't it be even bigger than N^2 (e.g. when I check for multiples of 1)?

  • »
    »
    15 months ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it

    For the O(NlogN) solution for outer loop you are going from 1 to n,for each i from 1 to n, you are marking it's multiples, we run inner loop on all numbers N/1 + N/2 + N/3 + N/4 + ..... + N/N times which equals O(NlogN)

    you can find here proof for why N/1 + N/2 + N/3 + ... + N/N is O(NlogN) https://stackoverflow.com/questions/53240625/formula-for-the-sum-of-nn-2n-3-n-n

    For the N*sqrt(N) soln you calculate all divisors of a number in O(sqrt(N))time ,you can refer this Primality tests and you do this for all N numbers Hence it is O(N*sqrt(N))

  • »
    »
    15 months ago, # ^ |
    Rev. 2   Vote: I like it +7 Vote: I do not like it

    I think that the easier way to look at this is:

    N/1+N/2+N/3+N/4+N/5+N/6+N/7+... < N + N/2+N/2 + N/4+N/4+N/4+N/4 +.. = N + 2*N/2 + 4*N/4 + .. + N*N/N = NlgN

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can Anyone explain me D Part pls?

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    First try to solve it for distinct elements.Traverse the multiples of every element and check whether this multiple is present in your array or not. If it is present then mark in your visited array that this element will not contribute in my answer. Your answer will be the n — sum(visited, visited + 1e6)

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Is it possible to find english editorials for ‌AtCoder contests? I want the editorial for E and F.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Just copy the Japanese text, and google translate it! I did the same, I think it's manageable

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

    check the editorial now, they have added english editorial too

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

Can someone provide some test cases for problem F?

Here is my submission (though i don't think it will help), I've used a dijkstra-based approach here.

My solution passes all TCs except 3, so i suspect that it may be failing on a corner case.

Any Help is appreciated.

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

    A small test case where your solution fails:

    Test
»
15 months ago, # |
  Vote: I like it -7 Vote: I do not like it

Anyone looking for readable code, go through AshishGup submissions, they are the most readable that i found.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks a lot for pointing it out. I learnt a lot from his solution to problem E.

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Where can I get editorials for the contest in English?? Specially for problems E and F!

»
15 months ago, # |
  Vote: I like it +13 Vote: I do not like it

Problem F is the same as 877D - Olya and Energy Drinks!

»
15 months ago, # |
  Vote: I like it +1 Vote: I do not like it

For Problem D:

It could be done so easily using dp and sieve method. Couldn’t realise on contest time :') Though dp is really <3 . Submission

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    can you explain the logic..??

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes it's similar to sieve of eratosthenes algorithm. We sorted the array here and marked every multiple upto largest element here.

      for 3 8 12 16 :

      we mark 3,6,9,12,15 and then 8,16..

      So finally we have 3=1,8=1,12=2,16=2. So it is clear 16,12 have multiple but 3 & 8 doesn’t have any multiple here. So, ans=2.

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

Test cases of the contest are not seen on dropbox. It shows that the file extension is not correct. Please fix it chokudai.

I had faced a similar problem to open test case file on other contests too.

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

Here is my submission for problem E. I used the approach of having vector of multisets and erasing the maximum and inserting again for every kindergarden using the approach mentioned in the tutorial, but i am getting TLE. Can someone help me why i am getting TLE.

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Why my solution is wrong for problem D?

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

What's wrong in my F submission?

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

    A small test for which your solution fails:

    Test
»
15 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Can someone provide me the link to that AC code for problem E in today's beginner contest which has used ordered multiset ( i.e. they should have used policy based data structures ) ?

It would be of great help.

I have solved the question using STL's multiset....but it's just that I'm curious about using them.

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

My accepted solution for Olya and Energy Drinks gives wrong answer on 2 testcases of problem F while the one using std::set approach passes. Why? :/

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    A small test where your solution fails:

    Test
  • »
    »
    15 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    MikeMirzayanov It seems like the problem 877D - Olya and Energy Drinks has weak test cases.

    My AC submission on codeforces also gave WA on AtCoder. An example of a failed test case is the following one provided to me by dush1729:

    Input
    Expected Output

    The following submission of mine outputs 5: 47925337, but it still gets AC on codeforces. I request you to add the above test case to 877D - Olya and Energy Drinks

    EDIT: Here's another test case which ShafinKhadem has mentioned in the comment just above mine:

    Input
    Expected Output

    My AC code 47925337 outputs 11 on this.

»
15 months ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

Why my submission for F works corectly locally, but CE on atcoder ?

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Which compiler are you using to compile locally? Your code gives me compile error locally, when I use GCC 9.3.0.

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

      gcc 5.1.0, is my version too old ?

      • »
        »
        »
        »
        15 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I won't say too old, but I think it's better to use updated version.

        • »
          »
          »
          »
          »
          15 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Thanks, I'll update it.

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

        Hi, I just tried compiling your code using GCC 5.1.0 too in godbolt. It gives compile error there. But in codeforces custom test, it compiles successfully. Which operating system are you using? Maybe your code gives CE only in linux.

        • »
          »
          »
          »
          »
          15 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          I think you're right, my operating system is win7.

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

          I found the reason! There is a header file called mathcalls.h in Linux and it has a function declared as double y1(double), so we cannot use #include<bits/stdc++.h> and declare y1 as a global variable at the same time in Linux!

          • »
            »
            »
            »
            »
            »
            15 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            A solution to this: add #define y1 yyyy1 in your template

        • »
          »
          »
          »
          »
          15 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Thanks a lot!

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone please tell what is wrong in my code for problem F? Link to my submission-->Link Any help will be highly appreciated.

Thanks!

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Hey ! Please provide copy button (for sample test case in Tasks for printing).

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It's already provided. (Actually, twice each)

    • »
      »
      »
      15 months ago, # ^ |
      Rev. 2   Vote: I like it +8 Vote: I do not like it

      I was talking about tasks for printing section

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

        I see. Perhaps it's no use writing here, and there's no official place to make suggestions, so maybe you have to write a UserScript or something...

»
15 months ago, # |
  Vote: I like it -10 Vote: I do not like it

can someone plz check my solution for problem D: three different way: 2 of which resulted in WA and 1 is right

approach 1:wrong answer O(n*sqrt(n))::

approach 2:wrong answer2 tried to optimised sieve ::

approach 3:correct

@ShafinKhadem @chokudai

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

If anyone need Problem D explanation with complexity analysis Here

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I had problem with C — Forbidden List I kinda ignored the part with abs_value just compared X and input array with a pre-made array (value set to 1-100). (code )since the input was limited i was pretty sure it will never get time limit error, it was wrong answer for two test cases and runtime error for two.

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone help me with the code of problem F?

first second

I dont konw why the second code will get wrong answer.The only difference between them is the transfers about direction.I think it just needs more time to run but not to mislead the answer. Can someone help me plzzz?Thanks a lot.