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

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

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

Идея: ibraevdmitriy

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

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

Идея: myav

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

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

Идея: myav

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

2000D - Right Left Wrong

Идея: Vladosiya

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

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

Идея: Vladosiya

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

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

Идея: ibraevdmitriy

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

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

Идея: ibraevdmitriy

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

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

Идея: ibraevdmitriy

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

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 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.

  • »
    »
    21 месяц назад, скрыть # ^ |
    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

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

      • »
        »
        »
        »
        21 месяц назад, скрыть # ^ |
         
        Проголосовать: нравится 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://mirror.codeforces.com/contest/2000/submission/276452095

  • »
    »
    21 месяц назад, скрыть # ^ |
     
    Проголосовать: нравится 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.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 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...

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

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

»
21 месяц назад, скрыть # |
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. )

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

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

276188663

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

H can be solved using segment tree. 276462150

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

How can I report suspected cheating in this round?

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +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://mirror.codeforces.com/contest/2000/submission/276433907

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 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)

  • »
    »
    21 месяц назад, скрыть # ^ |
     
    Проголосовать: нравится 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.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 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 ?

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

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

»
21 месяц назад, скрыть # |
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
»
21 месяц назад, скрыть # |
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
  • »
    »
    21 месяц назад, скрыть # ^ |
     
    Проголосовать: нравится 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.

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

did any one solved F using greedy?

»
21 месяц назад, скрыть # |
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
»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 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
  • »
    »
    21 месяц назад, скрыть # ^ |
     
    Проголосовать: нравится 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.

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

Why am I not official in this round !!!

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

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

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

is it possible to solve problem H using a segment tree

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

H can solve with segment tree, kadane and walking in the seg. if x is in the set, the value in the segment is -inf else 1

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

Solve H with using a segment tree:

Let's use that $$$a_i$$$ $$$\leq$$$ $$$C$$$, where $$$C=2*10^6$$$

Let's imagine an array $$$nxt$$$: if the set currently contains a number $$$i$$$, then $$$nxt[i]$$$ is equal to the number of elements starting with $$$i+1$$$ that are not in the set. That is, if the next higher number than $$$i$$$ in the set is $$$j$$$, then $$$nxt[i] = j - i - 1$$$. If there is no next number, then we must set it to $$$inf$$$ (or a number that is definitely sufficient for the problem, namely $$$2*10^6$$$). If the number $$$i$$$ is not in the set, then $$$nxt[i] = 0$$$.

Let's construct a segment tree for maximum on the array $$$nxt$$$.

Query responses are then processed as follows:

1) $$$nxt[i]$$$ can be updated by changing the value at a point in the segment tree, using std::set to maintain the set's elements and quickly find the next higher/lower element

2) answering a query is equivalent to finding the first element from the left in $$$nxt$$$ that is >= $$$k$$$. This is a standard problem that can be solved either using binsearch + prefix max queries using a segment tree, which will yield a $$$O(log^2 C)$$$ per query, or by descending the segment tree, which will yield $$$O(log C)$$$.

Also note that you can't reset the segment tree for each testcase, as this will result to $$$O(C*t)$$$ appearing in the asymptotics and exceeding the time limit. You can do it this way: after processing all queries, iterate through the set of remaining numbers and reset the segment tree at these positions. Then all changes will take a total of $$$O((n + q) * log C)$$$

It's $$$O((n + q) * log C)$$$

(you can see my solution for a better understanding)