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

Автор Vladosiya, история, 9 дней назад, перевод, По-русски

2000A - Первостепенная задача

Идея: senjougaharin

Разбор
Решение

2000B - Рассадка в автобусе

Идея: myav

Разбор
Решение

2000C - Числовой шаблон строки

Идея: myav

Разбор
Решение

2000D - Right Left Wrong

Идея: Vladosiya

Разбор
Решение

2000E - Фотосессия для горилл

Идея: Vladosiya

Разбор
Решение

2000F - Закрась строки и столбцы

Идея: senjougaharin

Разбор
Решение

2000G - Звонок во время пути

Идея: senjougaharin

Разбор
Решение

2000H - Ксюша и загруженное множество

Идея: senjougaharin

Разбор
Решение
Разбор задач Codeforces Round 966 (Div. 3)
  • Проголосовать: нравится
  • +30
  • Проголосовать: не нравится

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

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

Code

And also the issue with the algo pls.

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

    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

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

      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

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

        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.com/contest/2000/submission/276452095

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

          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

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

      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 :) .

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

    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.

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

      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

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

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...

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

    С++ is faster than java

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

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

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

    consider 2D adjacent difference it could be a lot easier

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

    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

»
9 дней назад, # |
Rev. 3   Проголосовать: нравится +17 Проголосовать: не нравится

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. )

»
9 дней назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

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

276188663

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

    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?

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

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

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

H can be solved using segment tree. 276462150

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

How can I report suspected cheating in this round?

»
9 дней назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

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

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

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.com/contest/2000/submission/276433907

  • »
    »
    9 дней назад, # ^ |
      Проголосовать: нравится +4 Проголосовать: не нравится

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

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

      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 << " ";
                  }
      
      • »
        »
        »
        »
        8 дней назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        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

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

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.com/contest/2000/submission/276453840

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

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)

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

    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.

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

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 ?

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

My Insights for A,B,C

Problem A
Problem B
Problem C

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

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

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

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

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
  • »
    »
    6 дней назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

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

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.

»
8 дней назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

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
  • »
    »
    5 дней назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.

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

    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

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

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

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

did any one solved F using greedy?

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

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

    4 18 5 4 8 5 8 3 6 2

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

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

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

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
»
5 дней назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

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

Thanks for the editorial ^_^

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

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
  • »
    »
    4 дня назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 дня назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Why am I not official in this round !!!