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

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

2051A - Подготовка к олимпиаде

Идея: BledDest

Разбор
Решение (Neon)

2051B - Путешествие

Идея: fcspartakm

Разбор
Решение (BledDest)

2051C - Подготовка к экзамену

Идея: BledDest

Разбор
Решение (BledDest)

2051D - Подсчет количества пар

Идея: fcspartakm

Разбор
Решение (BledDest)

2051E - Лучшая цена

Идея: BledDest

Разбор
Решение (Neon)

2051F - Джокер

Идея: BledDest

Разбор
Решение (Neon)

2051G - Змейки

Идея: BledDest

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

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

If tutorials for some problems aren't loading, they should be up in about 3-4 minutes.

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

    The E problem is really well designed. Initially, my understanding of the scanline algorithm was focused on processing points within a two-dimensional range. Therefore, when analyzing the E problem, I enumerated all the values of $$$~a_i~$$$ and $$$~b_i~$$$ and treated them as prices, which we denote as val. At this point, the number of buyers among those who would not leave negative reviews is the count of $$$~a_i~$$$ that are greater than or equal to val. The number of buyers who would leave negative reviews is the count of $$$~b_i~$$$ that are greater than or equal to val, under the condition that $$$~a_i~$$$ for that $$$~b_i~$$$ is greater than val. Thus, I viewed this problem as counting points within a two-dimensional range, applying a scanline approach combined with offline processing using a Fenwick tree. However, the complexity of this approach prevented me from implementing it during the competition. After the contest, I was able to see a similar application of the scanline thinking, and the profound understanding of it truly opened my eyes. This also led me to reflect on the essence of the scanline preprocessing, which is to update all necessary states in a legal time complexity according to a certain order. It made me reconsider that in my code design, I should focus on specific implementation steps rather than just thinking about which algorithm to apply. This experience has been very educational and helpful for me! I really appreciate the design of the problems you created!

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

For problem D, I felt so pathetic, if I would have realised earlier that there is no distinction between index i and j. I have solved same kind of question earlier, I would have solved it in contest as well as:(

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

E, input:

3 1
2 9 5
12 14 9

Why the answer is not 18 (2 * 9)?

1st customer: 9 <= b (negative review), 2nd customer: 9 <= a (positive review).

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

ty for great contest!

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

In E, a third method to optimize would be using PBDS, 297960644

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

Hi is there anyone able to solve G with python? My TSP seems too slow (currently at 7000ms). Also, it there any reason for the strict contraints, making it just a library check as even some C++ solutions are TLEing?

UPD: Got it AC

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

E is simple binary search on answer right? Or am I missing something?

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

    Binary search wont work because total earning w.r.t cost of the tree is not monotonus or unimodal.

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

      Why is it not unimodal?

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

        you can not be sure that if p is not a valid price then p+1 will also not be valid. Consider an example a = [6, 12, 12, 12] and b = [10, 20, 30, 40], and k = 0. Here the valid interval for a price could be [1, 6] but once the prices reaches 7, we will forced to buy the first tree, giving one negative review which is not allowed. The same will be the situation for 8, 9 and 10. But, once the price reaches 11 we can buy the remaining three trees with zero negative reviews. and beyond 12 we can again not buy anything. so the earnings increase in the interval [1, 6] then go to 0 in the range [7,10], peaking at 12 and again going to zero at beyond that. This behavior is not monotonic

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

          Can you help me find the bug in my approach 340085771 ? I tried finding highest possible price within the negative review limit by binary search (don't care about the profit now). Once I have that (let's call it highest_possible_price, I tried finding profit in 2 ways.

          • trying all possible a[i] and b[i] prices that are less than highest_possible_price and take the highest profit
          • instead of going over these prices linearly, I tried a ternary search as well. But I commented it out later since it's failing even on linear search so something is probably wrong at finding highest_possible_price.

          I'm really clueless even though I was pretty confident in my mind that it would work. Getting WA on 40th case of test 2 so can't check myself.

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

Why are O(nlogn) solutions getting hacked in E ?

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

    Maybe they get TLE? My O(nlogn) c++ solution barely fits in TL. 297985458

    • »
      »
      »
      16 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +1 Проголосовать: не нравится
      try this
»
16 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

why the testcases of the problems are opened?

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

https://mirror.codeforces.com/contest/2051/submission/297939657

in e problem i have done binary search on binary search , can you tell me why this will not work , basically what i did is first i did bs on profit , now to check if we can get profit x or not i have done binary search on price that what price we can keep so that it can give desired profit ??

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

For D: if two pointers do not solve problem, use 3 297969402.

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

Can Anyone give me hint for problem E? just hint for from where to start thinking process

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

anyone got AC following the alternate approach in E? im following a very similar approach but it fails my approach please help me out

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

Why my brute force solution doesn't work for D (I skipped C)? 297948999. It doesn't give TLE but it gives Wrong Answer on Test 3.

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

297858654 Can anyone tell me why this solution of C got hacked.

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

The judge gave an accepted verdict for my slightly wrong submission of Problem C during the contest, but in post-contest judgements I got WA on Test Case 10. :(

Idk if it was the issue with the judging software or the initial testcases were bad.

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

Did anyone else have a solution in C that gets WA on testcase 8 (although mine previously passed) because of a non-alphanumeric character showing? If yes, was this a bug on my side or a bug on Codeforces?

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

Obviously the problem E is binary search. For anyone here is the solution pretty straight forward.

Solution

  1. Observation only the cost values of ai and bi matters either take a penalty with maximum hit or don't. Any other values in between don't make any sense.

  2. Binary search if the cost is C then how many people can buy it happily and how many can't buy at all.

  3. Calcuate the penalty from these 2 values which is just total people — people who can buy happy — people who cannot buy at all and then see if penalty people are in our limit

  4. If in our limit take the current cost and go on max of all such costs.

I was 7 minutes late in contest. Observation 3 got me. I thought its in my best interest if I want to sell or not but apparently I have to sell if the customer can afford because "the customer is always right".

PS: How to approach F in simple language?

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

    If intially u have joker at 5th positon . if a0<5 it will occupy 4th and 5th position , if a0>5 it will occupy 5th and 6th position . so doing this u will get that joker will occupy from l to r . now if ai<l l--,else if ai>r r++ else the joker will also occupy 1st and nth position . now keep doing the same thing assuming u have 3 segments 1 to l1 , l to r and r2 to n

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

Here is my solution to the Problem E which i find really interesting.

Firstly i hash all the values with the index of the vector then i count the values which might leave the negative review using a difference array which is values that are a[i]+1 to b[i] after that i iterate for the values and calculate the cost for which has k or less negative review.

Submission : 297938827

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

F was smart

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

F is so hard. I can't imagine F being a question about segments.

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

Is the rating updated for you guys? This is taking a bit longer than usual.

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

For F , how to get 5 in the first example?I only get [2 , 3 , 4 , 5]

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

This round really preserved the beauty of Educational Rounds as the authors are the same... sadly, I could not attend it live and had to participate virtually.

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

What would be the difficulty rating of problem E and F? clist.by says 1980 for E and 2349 for F but I don't think it's that much, no?

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

My submission 298069513 for Problem E is giving wrong answer in testcase 2. Can anyone please help out why this is happening and at what testcase it fails? bcoz according to me my logic seems correct.

Thanks

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

Here a super-easy and clean implementation of problem E using upper_bound to find number of positive and negative reviews without creating new arrays (just sorting the original ones with negative values): 297888481

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

Shouldn't the test case for D, 7 10 13 4 2 5 2 4 3 1

be giving 3 instead of 4. What am I missing here?

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

Could anyone explain why O(n^2*q + 2^n * n ^ 2) solution for problem G works for n <= 20 and q <= 2*10^5? I normally suppose that 10^8 operations will be run in 1 second, so this solution runtime should be more than 4s.

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

I find my solution to D to be much simpler than the editorial's--the only downside is that it uses PBDS: https://mirror.codeforces.com/contest/2051/submission/299348552

I think the code is self-explanatory (ignoring the indentation and other weird quirks.)

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

can anyone tell me why my code is not passed 3rd test case for problem b https://mirror.codeforces.com/contest/2051/submission/319545029

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

my solution for E — > ~~~~~ int countLessThan(vector& arr, int x) { int lo = 0, hi = arr.size(); while (lo < hi) { int mid = lo + (hi — lo) / 2; if (arr[mid] < x) lo = mid + 1; else hi = mid; } return lo; }

int countGreaterEqual(vector& arr, int x) { int lo = 0, hi = arr.size(); while (lo < hi) { int mid = lo + (hi — lo) / 2; if (arr[mid] < x) lo = mid + 1; else hi = mid; } return arr.size() — lo; }

void solve() {

int n, k;
cin >> n >> k;

vector<int> a(n), b(n);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) cin >> b[i];

sort(a.begin(), a.end());
sort(b.begin(), b.end());

int res = 0;


for(int i = 0; i < n; i++) {
    int c2 = countLessThan(a, a[i]);
    int c3 = countLessThan(b, a[i]);
    if(c2 - c3 <= k) {
        int cnt = countGreaterEqual(b, a[i]);
        res = max(res, cnt * a[i]);
    }
}


for(int i = 0; i < n; i++) {
    int cnt = countLessThan(a, b[i]);
    int c3 = countLessThan(b, b[i]);
    int c2 = countGreaterEqual(b, b[i]);
    if(cnt - c3 <= k || c2 <= k) {
        res = max(res, b[i] * c2);
    }
}

cout << res << endl;

} ~~~~~

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

MY SOLUTION FOR E ->

int countLessThan(const vector<int>& arr, int x) {
    int lo = 0, hi = arr.size();
    while (lo < hi) {
        int mid = lo + (hi &mdash; lo) / 2;
        if (arr[mid] < x) lo = mid + 1;
        else hi = mid;
    }
    return lo;
}


int countGreaterEqual(const vector<int>& arr, int x) {
    int lo = 0, hi = arr.size();
    while (lo < hi) {
        int mid = lo + (hi &mdash; lo) / 2;
        if (arr[mid] < x) lo = mid + 1;
        else hi = mid;
    }
    return arr.size() &mdash; lo;
}


void solve() {

    int n, k;
    cin >> n >> k;

    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    int res = 0;


    for(int i = 0; i < n; i++) {
        int c2 = countLessThan(a, a[i]);
        int c3 = countLessThan(b, a[i]);
        if(c2 - c3 <= k) {
            int cnt = countGreaterEqual(b, a[i]);
            res = max(res, cnt * a[i]);
        }
    }


    for(int i = 0; i < n; i++) {
        int cnt = countLessThan(a, b[i]);
        int c3 = countLessThan(b, b[i]);
        int c2 = countGreaterEqual(b, b[i]);
        if(cnt - c3 <= k || c2 <= k) {
            res = max(res, b[i] * c2);
        }
    }

    cout << res << endl;

}