Vladosiya's blog

By Vladosiya, history, 4 weeks ago, In English

2000A - Primary Task

Idea: senjougaharin

Tutorial
Solution

2000B - Seating in a Bus

Idea: myav

Tutorial
Solution

2000C - Numeric String Template

Idea: myav

Tutorial
Solution

2000D - Right Left Wrong

Idea: Vladosiya

Tutorial
Solution

2000E - Photoshoot for Gorillas

Idea: Vladosiya

Tutorial
Solution

2000F - Color Rows and Columns

Idea: senjougaharin

Tutorial
Solution

2000G - Call During the Journey

Idea: senjougaharin

Tutorial
Solution

2000H - Ksyusha and the Loaded Set

Idea: senjougaharin

Tutorial
Solution
  • Vote: I like it
  • +27
  • Vote: I do not like it

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

can anyone pls tell why this code is getting a runtime error. for Problem D

Code

And also the issue with the algo pls.

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

    consider the case where there are no 'R' in the string. in this scenario, your 'right' variable would be initialized with the value -1

    edit : avoid using C++17 (GCC 7-32) and use C++20 (GCC 13-64) instead

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

      you mean something like this -> n = 6, a(n) = 1 1 1 1 1 1 s = LLLLLL -> and the output should be 0 right. actually I checked this one already and it gives me 0 perfectly fine. Cause I'm checking the out of bound condition before using those

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

        I admit I do not know much about C++17 (32-bit), but if I had to guess, this particular error might be occurring because your while loop condition:

        while(left < leftsig.size() && right >= 0 && leftsig[left] < rightsig[right]) {

        is not stopping after right >= 0 evaluates to false. Instead, it continues evaluating leftsig[left] < rightsig[right], which could cause an access violation if right is -1 and thus result in the error

        you can fix it by choosing C++20 (GCC 13-64) as your compiler when you submit the code

        https://codeforces.net/contest/2000/submission/276452095

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

          yeah I guess C++17 doesn't stop when a condition is false in the loop conditions, untill it checks all the conditions

          edit: I used the prefix sum to avoid tle and it went ohk

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

      oh thanks for the help it went perfectly just by changing this. Wasn't expecting it to be this sort of issue, will use C++ 20 always :) .

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

    This solution will give tle as you are calculating sum of subarray again and again. Instead use prefix sum to get the sum of the subarray.

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

      I did that that in the updated code here ->

      Code

      But this still gives me runtime error edit : after changing from C++17 to C++20 this works perfectly fine and thanks for the prefix sum intuition

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

I need help

Can anyone tell me why my solution in proplem E got TLE when i write it in java , but when i write the same code in c++ i got AC

java solution --> Your text to link here...

c++ solution --> Your text to link here...

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

someone explain how to intuit the way they count it in problem E please.

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

    consider 2D adjacent difference it could be a lot easier

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

    do u know diffrence array? to update values in range for 1d vector it can be used here to count for 2d vector then 2d prefix sum

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

I am impressed by how treap is being casually used in a div3 contest editorial (problem H).

(Context: Of course I am well aware that this is not how most contestants solved, or are supposed to solve it, but rather make use of the (non-essential) constraints max <= 2e6. It is also clear that a fully online solution of this without the extra constraints will have to involve your favourite BBST. Though, I don't know how many people will get confused by the editorial. )

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

    They took the effort to explain the std::set part but not the treap part :)

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

    If possible can you explain how to do it without treap? I was thinking of a solution where I can maintain an array where the indices represent the lengths of the free segments and the value at that index is the value of the left border of that segment, then I just need to find suffix minimums to answer any query. I was thinking of using segment tree for handling updates and suffix range queries, but I think that will TL because there is no bound on sum of $$$max(a_i)$$$ across all test cases and my time complexity would become $$$O(T\cdot max(a_i) \cdot\log{max(a_i)})$$$ in that case.

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

      You can reuse the same segment tree. So initialise one segment tree with size max(a_i), at the end of each test case you undo all insertions.

      I take that you already know how to "find first index in segment tree that is >= some value", but for others this can be handled by using a max-segment tree and a standard segment tree descend

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

    treap sounds like something you cover a pool with

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

for E, I completely missed the n*m<=2e5 bound and coded a O(nlogn + mlogm + wlog(n*m)) solution

276188663

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

    I also misread the n*m<=2e5 constraint, and I tried to code a bfs type solution starting from the center of the grid where we greedily visit cells in the graph that have the most subarrays containing them. I failed in the implementation, but is your solution idea similar?

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

    I got scared when I didn't see the n*m <= 2e5 condition and I immediately re-checked the problem statement :)

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

H can be solved using segment tree. 276462150

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

How can I report suspected cheating in this round?

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

please help me with my submissions for C. I've used a map for int to char mapping, and then a vector of size 26 for char to in mapping. My conditions are also correct (acc to me) so please if anyone can see why is my code failing please help me ! I am getting WA on test 18.

276216688

so i just changed my code to use 2 maps instead of 1 map + 1 vector and it got accepted. why did this happen ?

276481407

i solved it.. i was initializing vector with -1 which is wrong. i made it INT_MIN and it worked

276482552

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

The problem H has a beautiful solution using sqrt decomposition (It works slower than the author's solution, but it seems to me easier to understand and write). My example solution: https://codeforces.net/contest/2000/submission/276433907

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

    Problem H Solution without any specific method/data structure but only logic — 276496494

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

      what is the time complexity of this block?

      auto fitr = que.lower_bound(x);
                  if(fitr == que.end()) cout << -1 << " ";
                  else {
                      int mini = INT_MAX;
                      for(; fitr != que.end();) {
                          mini = min(mini, *(fitr->second.begin()));
                          fitr = next(fitr);
                      }
       
                      cout << mini << " ";
                  }
      
      • »
        »
        »
        »
        4 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Worst case is ~ $$$\sqrt {2 . 10^6}$$$. When the set has 2e6-1, 2e6-4, 2e6-8, 2e6-13, .... and the query is "? 1" ig

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

For problem D, I know that it can be solved using 2 pointers or manually matching the L's with R's, but still I can't figure out what is wrong with my solution, it gives Wrong Answer on Test 7, i.e. it is working for smaller inputs but not for larger ones, (maybe, I don't know). It would be very helpful, if someone could point out the idea that I am missing.

My Submission: https://codeforces.net/contest/2000/submission/276453840

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

Can someone explain me Problem F in detail? I saw shayan's vid but I keep getting lost. (I have a fair experience with dp)

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

    The hardest part of this problem is understanding optimal way of painting single rectangle. Like they say in editorial you must always choose to paint single column or row of minimum size. For example, if you have 3 by 4 rectangle you unpainted rectangle will change like this: 3x4 -> 3x3 -> 3x2 (or 2x3, does not matter) -> 2x2 -> 2x1 (or 1x2) -> 1x1 -> 0x0 Every transition will give you one score point (except for last which gives 2 points because we paint one row and one column at the same time). You perform this sequence of operations on the first rectangle, keep track on the number of operations (cnt1) and score (s), calculate recursively min. number of operations for the rest of the rectangles to achieve (k — s) score (cnt2), choose min(cnt1 + cnt2) after painting sequence is complete.

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

can someone explain, why the sample testcase 1 answer is 0. I think we can wait upto 19 minutes and then take the bus route 1 — 5 which will cost 30 minutes, and we will arrive on 5 at 49 minutes ?

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

    You cannot ride a bus during entire phone call, not just start of it.

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

My Insights for A,B,C

Problem A
Problem B
Problem C

$$$\text{Nice Educational Contest overall !}$$$

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

Can anyone help me find out the test case for which 276261336 problem C (test case 18), failed ?. Appreciate any help thank you :)

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

    I found this test case:

    Test

    which in my code returns:

    Result

    and in yours:

    Result

    Hope it helps!

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

For problem G sample 1, can someone share the route which corresponds to a starting time of 0? From what I understand of the problem, there should be no solution and the answer should be -1. Maybe I am overlooking something. I am copying the sample below for convenience.

5 5
100 20 80
1 5 30 100
1 2 20 50
2 3 20 50
3 4 20 50
4 5 20 50
  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    In time 0, walk through the edge from 1 to 5. That will take 100 units of time, which fits in t0.

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

For problem E, the image in the Notes section loaded for me without any gorillas and I lost a lot of time trying to make sense of the image.

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

For Problem F, sample 6, reproduced below, can someone explain how the required 25 points can be obtained in 80 operations, as given in the sample solution?

3 25
9 2
4 3
8 10
  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    First we will completely fill the 2*9 and 4*3 rectangles. After this our score would be 18 and operations are 30. After this we will start filling the 8*10 rectangle in this order — 8, 8, 8, 7, 7, 6, 6. This would lead to a total score of 25 in 80 operations.

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

    Take all 9x2 for 11 points, take all 4x3 for 7 points, take all but a 5x6 rectangle from 8x10 (which is 50 squares) for 7 points. 8+8 + 8+7 + 7+6 + 6 = 50 11+7+7 =25, 18+12+50=80

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

are there public solutions using python? as i am currently learning python and want to master it before starting c++

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

did any one solved F using greedy?

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

    Can you tell me how 35 operations are required in last test case

    4 18 5 4 8 5 8 3 6 2

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

      Use entire first and last rectangle and then use rectangle which is having b = 3 to make the score 18

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

Can anyone please explain what's wrong in my approach of problem G. I applied binary search to find how late we can start to reach on time. What I'm doing in my modified dijkstra is that if I can take bus then then will take it but if I will get a call in between or currently on a call then I will take the best of wait till the call is finish and take bus or walk.

My Code
»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Is there anyone who solved problem G using python? My code exceeded time limit on test 17.

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

Thanks for the editorial ^_^

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

Can someone please explain me how are we getting 35 operations in last test case of sample? I am getting 36 operations to score 18 points.

4 18

5 4

8 5

8 3

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

    Fill the 6 x 2 (score = 8 & operations = 12) rectangle and 5 x 4 rectangle (score = 9 & operations = 20) completely and one row of 8 x 3 rectangle (score = 1 & operations = 3). Therefore total operations and score would be 12 + 20 + 3 = 35 and 8 + 9 + 1 = 18 respectively.

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

Why am I not official in this round !!!

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

In problem G, why did I get TLE when I used priority_queue but after switching to set<pair<int,int>> it became AC?

»
13 days ago, # |
  Vote: I like it 0 Vote: I do not like it

I am only into dsa, can that help me in cp. I am new to this field

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

In problem H, I am getting WA, Can someone explain what am I doing wrong.

I am trying to maintain the free segments and updation using multiset. I am maintaining (dist, left_endpoint) in the multiset and the points currently in the set. Then I am performing the insertion and removal operation by taking the next and previous points from the points set.

Link to my solution: submission

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

    I did the same thing with you, and also got WA in test case 2.

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

      Were you able to solve the issue??

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

        I can not, but I do not know why. It seems quite right to me.

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I have a test case totay and my code gets the wrong answer. Now I find the problem in my code with this case. You can test yours. input: 1 6 1 4 6 7 8 9 3 ? 5 + 10 ? 1 output 10 2

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes my code is also failing this TC. The issue is that since I have sorted the multiset based on distance so there might be a smaller point later on but with a bigger distance. I need to find the lowest value available in suffix of distances starting from k.