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

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

1974A - Рабочий стол телефона

Идея: Aksenov239

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

1974B - Симметричное кодирование

Идея: MikeMirzayanov

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

1974C - Красивые пары троек

Идея: MikeMirzayanov

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

1974D - Ingenuity-2

Идея: MaxBuzz

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

1974E - Деньги покупают счастье

Идея: RobinFromTheHood

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

1974F - Игра с отрезанием

Идея: MikeMirzayanov

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

1974G - Деньги теперь покупают меньше счастья

Идея: RobinFromTheHood, izban, Aksenov239

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

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

Thanks for the contest ! Good Problems !

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

Thank you for the excellent coordination and organization! I joked about physicists because I am one :)
Please encourage all physicists to code!

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

    guys... In problem C why are we subtracting count of triplets form answer (- cnt.get(triplet, 0) ) from our answer each time we add cnt.get(trip, 0) ?

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

      if 111 has already been come accross, then the cnt dict already contains extra 110,101 and 011 corresponding to it. These three triples should not be counted as beautiful if we come across 111 again.

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

      To avoid counting same triplets as a beautiful pair. For example, if you are currently dealing with the triplet "321" then you are inserting 301, 021, 320 and 321 itself into the cnt dictionary. Now, if you come across "321" again in the array then "321" and "321" should not be counted as a beautiful pair. So you have to subtract the count of same triplets.

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

Thanks for the good contest Graet Problems

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

Problem C was quite tough than average!! Acceptance rate is less than 50%. Anyways another good round by Vladosiya

»
5 недель назад, # |
Rev. 3   Проголосовать: нравится +18 Проголосовать: не нравится
Simplest Implementation for Problem D
  • »
    »
    5 недель назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    This is really clean. I was thinking the same idea but it turned out to be way complicated when I actually coded it. Thank you!

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

can someone explain Q3 solution?

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

    For a more functional explanation: to avoid redundant counting, we'll iterate once through every triplets, count every triplet to the left of it that would make a beautiful pair.

    In notation, denoting $$$cnt(x)$$$ is the current counter for triplet $$$x$$$, then for each triplet $$$(a_i, a_{i+1}, a_{i+2})$$$ being iterated:

    • Add $$$cnt((0, a_{i+1}, a_{i+2})) + cnt((a_i, 0, a_{i+2})) + cnt((a_i, a_{i+1}, 0))$$$ to the final answer. This is the process of pairing the current triplet with the ones before it that have at most one error.
    • Still, we need the two triplets to have precisely one error actually. So the completely identical pair(s) must be excluded. Therefore, subtract $$$3 \times cnt((a_i, a_{i+1}, a_{i+2}))$$$ from the final answer. The constant factor $$$3$$$ was because if there were any such element, they would have been counted $$$3$$$ times at the previous steps.
    • Add $$$1$$$ to $$$cnt((a_i, a_{i+1}, a_{i+2}))$$$, $$$cnt((0, a_{i+1}, a_{i+2}))$$$, $$$cnt((a_i, 0, a_{i+2}))$$$ and $$$cnt((a_i, a_{i+1}, 0))$$$. This is to include the current triplet to be counted at further iterations.

    Take the 8th test in the sample:

    5
    2 1 1 1 1
    

    We'd have three triplets, $$$(2, 1, 1)$$$, $$$(1, 1, 1)$$$ and $$$(1, 1, 1)$$$, and initially $$$ans = 0$$$.

    • Iterate through the first. It's obvious that answer remains at $$$0$$$ because there's nothing to the left of it to pair with. Still, after this, $$$cnt((2,1,1))=cnt((0,1,1))=cnt((2,0,1))=cnt((2,1,0))=1$$$.
    • Iterate through the second. We can add $$$cnt((0,1,1))+cnt((1,0,1))+cnt((1,1,0))=1+0+0=1$$$ to the final answer, thus now $$$ans = 1$$$. Also, now $$$cnt((2,1,1))=1$$$, $$$cnt((1,1,1))=1$$$, $$$cnt((0,1,1))=2$$$, $$$cnt((2,0,1))=cnt((2,1,0))=cnt((1,0,1))=cnt((1,1,0))=1$$$.
    • Iterate through the third. We add $$$cnt((0,1,1))+cnt((1,0,1))+cnt((1,1,0))=2+1+1=4$$$, yet we have to subtract $$$3 \times cnt((1,1,1)) = 3 \times 1 = 3$$$, therefore final answer is $$$2$$$.
»
5 недель назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

For Task 5, my recursive code works fine, but on memoizing, it gives a different answer on the last sample case, Why is this happening, and how to rectify it?

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

    There are 3 changing states in your code i,e curr_month , happiness , salary but the dp you have created is consisting of only 2 variables.

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

      Got it, now I tried two other approaches: Both get TLE at 10 Case 262001589 262002708, Can you please look into this and help?

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

        For a 3-D dp, the number of states are too much to pass the case 10. hence it fails

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

          Shouldn't it pass with map, it will store only feasible combinations? 50(m)*50(type of h)*50(type of rem salary) = 1.25*1e5

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

            How can the tc be 50*50*50. There are 50 months and the number of ways to choose them are 2^50 . The upper bound of your code can be (50 *1e8 * 1e3) . But due to memoization it will be lower than that. Lets suppose all of the values of costare such that sum of any subset taken will be different then there will be large number of different values of cost so your map will have a huge amount of keys . But as we can see the happiness is 1e3 at max , so the total happiness can be upto 50 * 1000 ie 5e4 (where as cost can change upto 1e8 * 50) . So somehow you need to make your dp dependent on only index and happiness at max.

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

    I was struggling with the same issue for over a couple of hours, I recommend 261999415, there's a minor constraint that u need to consider.

    If for a particular happiness value, If we have more amount with me in some other recursive call, i need not implement my current recursive call with a lower amount left with me, because that shall cause an issue in the future.

    Because we have 3 parameters to consider, we have to consider also the amount that we spend for a particular index with particular happiness value, for which i have used the sp matrix.

    Hope that helps !

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

      If for a particular happiness value, If we have more amount with me in some other recursive call, i need not implement my current recursive call with a lower amount left with me, because that shall cause an issue in the future

      here what do you mean by issue in future? can you explain it further?

      also can you find out error in my code?262040594

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

    salary can get up to 1e9 so we can't store it as a state, I'm not quite sure yet but I think this classical problem will help you solve E : https://atcoder.jp/contests/dp/tasks/dp_e

    it's knapsack but with a technique called dimension rotation

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

It 's sad that we didn 't even have time to read the problem 1974E - Money Buys Happiness, because of the long code in 1974D - Ingenuity-2 . Despite this, the problems were very good.

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

I wonder how submissions increases rapidly in the last half hour

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

Python Forces ! , Thanks Vladosiya

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

In my opinion, questions were really good, but quite implementation based (at least in C++).

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

Here's an alternate solution for problem C using only sorting: solution (C++)

The solution is not so fast since I have used sorting 3 times, but it is nonetheless O(n logn)

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

    Sorting 3 times is fast (proof: 261990288), passing vector of vectors to calc is slow

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

      ohhh shoot

      I can't believe I passed vector by value. I realized that just now. Wrote many c++ programs but never made that mistake, and today I did it TT.

      This solution deserved to TLE. Thank you for pointing out the real bottleneck of the solution, I need to be a lot more mindful next time onwards, ig.

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

    we can also apply principle of exclusion and inclusion by help of nested maps but that can be space inefficient solution but here it worked.

        #define int long long
        int n;
        cin >> n;
        vector<int> nums(n, 0);
        for (int i = 0; i < n; i++) cin >> nums[i];
        int ans = 0;
        map<int, map<int, int>> mp1,mp2,mp3;
        map<int, map<int, map<int, int>>> mp;
        for (int i = 0; i < n - 2; i++)
        {
            ans +=   mp1[nums[i]][nums[i + 1]] 
                    + mp2[nums[i]][nums[i + 2]] 
                    + mp3[nums[i + 1]][nums[i + 2]] 
                    - 3*mp[nums[i]][nums[i + 1]][nums[i + 2]];
            mp1[nums[i]][nums[i + 1]]++;
            mp2[nums[i]][nums[i + 2]]++;
            mp3[nums[i + 1]][nums[i + 2]]++;
            mp[nums[i]][nums[i + 1]][nums[i + 2]]++;
        }
        cout<<ans<<endl;
    
    • »
      »
      »
      5 недель назад, # ^ |
      Rev. 2   Проголосовать: нравится +4 Проголосовать: не нравится

      tuple can be used instead of in nested map mp, storing the exact same triple: map<tuple<int, int, int>, int> similar;

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

        Thanks for your valuable suggestion

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

        Thank you so much! Tuple make my code much simpler. I don't know why my first implement of my idea using map<string, int> wrong answer on test 7. Then I implement the same idea with map<tuple<int, int, int>, int> and got accept. I'm really confused. Here is two version of my code 262693385 and 262688887, Could someone please point out my mistake in version of the code that uses map<string, int>?

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

In question C , it is given 4 seconds , as per what i know one second has 10^8 iterations , so 4 sec should have 10^32 iterations and max n value is 2*10^5 , so n^2 soln at worst has 4*10^10 iterations and max testcases are 10^4 so an overall T.C of 4*10^14 which is approx 2 sec , but why n^2 solns got failed , im just curious , i did using map ,but got tle in bruteforce , please correct me if i am wrong .

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

    in 4 seconds, we should have atmost 4*(10^8) iterations not 10^32.you had done mathematical error.

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

    If you're assuming 1 second = $$$10^8$$$, then 4 second is $$$4 \times 10^8$$$, not $$$10^{32}$$$. $$$10^{32}$$$ is 1000000000000000000000000 times larger than $$$10^8$$$.

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

      my bad , sorry for wrong calculation , lol all these days i was doing wrong calculation .

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

Problem G has to be Antimatter Dimensions-inspired. Which one of you writers plays the game?

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

my solution to d which was the most troll solution I've ever written. I just brute-forced while trying to have device 2 follow the path of device 1. I was very unsure of it passing but it somehow got AC. Can someone please help in formal proof (not mathematical) of why this works? submission: 261894801

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

    hahaha I think that's very funny, especially because I did basically the same thing. You can think of it this way, the two objects alternate between accepting each type of instruction. It might be easier to understand with my code. 262066699

    So there are four (but only two that pass) cases when we restrict ourselves to one dimension, either y or x, let's just choose y for now. So the amount of upwards instructions is either even or odd, and the amount of downwards instructions is also either even or odd. Ignoring the two cases where they have opposite parities, there are two cases left, where they are either both even or both odd. If they are both even, they will obviously end up at the same point, they will both receive the same amount of instructions. Then, there is the case where both instructions are odd. If the first object takes one extra up and one extra down instruction, it essentially doesn't move, and we now have an even amount of upwards and downwards instructions, which just reduces to our first case. We can also apply the same logic to the x dimension, leading to the solution.

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

Can someone explain to me, why my code for Problem C is giving WA on test case 8, it got accepted during the contest, but failed in System testing.

261837444

  • »
    »
    5 недель назад, # ^ |
    Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится
    ans-=j.second*j.second;
    

    Those lines in your code seem to be very questionable overflows (as the map key/values are all pair<int, int>, tested with C++17 32bit to make sure int is 32bit). Resubmitting with pair<ll, ll> passed that test.

    I don't really know how it escaped the original testset.

    Quick fix without changing data type:

    ans-=1LL*j.second*j.second;
    
»
5 недель назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

Anyone else used Segment Trees on problem G?

It's a bit of an overkill, but it was my first idea and it worked.

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

    yea even i felt seg tree was the most instictive solution, but turned out the problem was pretty simple

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

Good Problems!

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

problem E is exactly same as Knapsack -2 from Atcoder dp contest. Just add the extra condition: on any given month , if minimum cost required to come up with happiness h should be less than the money earned till the previous month.

Check out my submission here : 261998965.

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

    Yup its state rotation idea

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

    can you please tell me what am i doing wrong here??

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

      you need to check the following:

      if(min(take,dont)>i*x)return dp[i][hap] = 1e10;
      

      I think this could solve the issue for now.

      However, I guess recursive solution is giving TLE. I did bottom-up and that got accepted

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

        Hey I have used the same concept as knapsack 2 only but did using recursion...but I am getting wrong answer on test case 14... Can you help me in finding out the error? 262061702

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

    I need help with time complexity Since m is 50,and no. of testcases are 1000. Sum of m over all testcases should be 5e4 which after multiplying with 1e5(sum of Σh over all testcases) comes out to be 5e9. And 5e9 should give TLE.

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

Hi everyone, can someone explain the idea behind how we would arrive at this solution? Specifically why theres a mp['W'] + 1 and mp['E'] + 1? and not for N and S?

void solve() { ll n; cin >> n; string s; cin >> s; map<char, ll> mp, rover; lp(i, n) mp[s[i]]++; if ((mp['S'] + mp['N']) % 2 == 0 && (mp['E'] + mp['W']) % 2 == 0 && (n > 2 || s[0] == s[1])) { rover['N'] = mp['N'] / 2; rover['S'] = mp['S'] / 2; rover['W'] = (mp['W'] + 1) / 2; rover['E'] = (mp['E'] + 1) / 2; lp(i, n) { if (rover[s[i]] > 0) cout << 'R'; else cout << 'H'; rover[s[i]]--; } cout << endl; } else { cout << "NO" << endl; } }

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

One of the concise and clear implementation of problem D-

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

why this gives TLE on case 10 — Problem E

map<pair<int, int>, int> mp;

int sol( int j, int l, int x, vector<array<int, 2>>& v ){
   if( j >= v.size() ) return 0;
   if( mp.count( { j,l } ) )
      return mp[ {j, l} ];
   int res = sol( j + 1, l + x, x, v );
   res = sol( j + 1, l + x, x, v );
   if( l >= v[ j ][ 0 ] )
      res = max( res, v[ j ][ 1 ] + sol( j + 1, l + x - v[ j ][ 0 ], x, v ) );
   return mp[ {j, l} ] = res;
   }

void __(){
   int n, x;
   scan( n, x );
   vector<array<int, 2>> v( n );
   for( int i = 0; i < n; i++ ){
      scan( v[ i ][ 0 ], v[ i ][ 1 ] );
      }
   int ans = sol( 0, 0, x, v );
   print( ans );
   mp.clear();
   cout << "\n";
   }
»
5 недель назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

5th question me DP itna aasaan tha ki me agle Janam me bhi naa kar paun(laughing emoji-2)

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

The statement for F is really easy to misread. The problem statements use (x, y) variables for (row, columns)

Given we're cutting on left and right, one would expect that was against the x variable, but it is against the y variable, and up / down cuts are against the y variables. I'll be more careful when reading, but that is slightly unfriendly to the reader.

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

Easiest G ever:)

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

In question F, my approach was to keep track of every y coordinate containing a chip for each row(same for column) in vectors, and maintain two pointers for rows and columns. And if there is a row being erased(similarly for column), I applied binary search to get the index of smallest and largest indices within the range bound by the two pointers for columns, to add to the scores.

But the submission is giving memory-limit-exceeded. 262010194

Can anyone identify the reason, I think the total space I am using is in order the O(n).

  • »
    »
    5 недель назад, # ^ |
    Rev. 3   Проголосовать: нравится +3 Проголосовать: не нравится
    row[x1].size()>0
    

    Be extra careful at such lines. If x1 isn't yet in the map, the map will allocate a new "block" of memory for that key, and thus as time goes on, it'll keep populating until MLE.

    That doesn't yet consider the fact that for(int j=0; j<sh; j++) will TLE eventually (as the sum of sh in each test can reach $$$2 \cdot 10^9 - 2$$$ at maximum), but usually MLE will come first if possible anyway.

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

Hey Vladosiya

It appears there's an issue in the tutorial where the directions for how N and S affect the variable y are incorrectly stated. The current explanation mentions that N decreases y by 1 and S increases y by 1. However, N should increase y by 1 and S should decrease y by 1.

Thanks.

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

    Actually it does not really matter, as long as everything is consistent in the code. Swapping the directions just mirrors the picture, but does not change whether a certain answer is correct or not.

    But surely the NS-polarity does not agree with the attached solution (while the tutorial is supposedly an adaptation of my original analysis, the solution is not mine), so, Vladosiya, it is definitely better to make these the same.

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

You can observe that it is similar to classic knapsack but the constraints are different. here the maximum salary you can get is (m-1)*x which is nearly 1e8 range..so you can't store it as state. So now you have to see the problem in another way.. i.e. you know what is the maximum happiness you can get and i.e equal to sum of all happiness now you have to start from this maximum value of happiness till zero see for which happiness you got cost <=((m-1)*x)..and return it as answer so here your states will be f(index,happiness)

Caution : 

Don't use memoization.. you will get TLE.. try to use tabulation method For reference you can check my submission 262090006 For reference video you can check out this (but in hindi language) — video

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

Please share the editorial solutions in C++ too.

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

I got MLE in problem E. I'm using memoization to calculate the max happiness. Can anyone help me in optimizing the Memory in my code?

262108607

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

    You are defining some dp[m][m * x], although m <= 50, but x is too large x <= 10 ^ 8. You are in total allocating m ^ 2 * x ints, which take a memory of (4 * 50 * 50 * 10^8)B = 1000GB.

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

Who can teach me g questions orz. I can not understand the solution.(qwq)

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

    the question G is a modification of question E, but in this case the happiness values is assigned 1.

    My algorithm: I used a greedy algorithm for solving the problem. I bought happiness in the current month and added it to my bought list. If at any month I am not able to afford it, then I removed the most expensive happiness from by bought list (i.e. not bought it).

    Submission 262189832

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

good contest!

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

I am confused with Task-C and Kotlin.

Don't understand why this is TL https://codeforces.net/contest/1974/submission/262119536

and this is OK. https://codeforces.net/contest/1974/submission/262120101

The only difference is in keys of map. In the first case it is data class(x,y,z), in the seconde it is String "$x_$y_$z". For some reason solution with data class works very slow. Any guru of kotlin for help?

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

For problem E, Why does this code 262139086 TLE on test 14 ? It uses the same idea as in the editorial and has the same time complexity.

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

    maybe due to the fact the j loop is going till 50000 instead of the sum of maximum happiness , have seen a similar problem happen to another user

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

      yeah, but in the worst case, won't the sum of maximum happiness be around 50000 ?

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

        yeah but the maximum sum of happiness over all test cases has an upperbound given by 10^5 as written in the last statement in the problem . Iterating over 50000 over a 1000 test cases breaches that limit , so taking the worst scenario every time doesn't help us here

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

    custom mashup I created a private mashup for it where i submitted 262139086, it took 15 sec.

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

For those stuck in G, here's the same idea 105123E - Powerhouse of the Cell?

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

someone please suggest the sources you practise problem e. and similar ones for practising dp.im a newbie here want to learn dsa first.

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

hey MikeMirzayanov what is this partial behaviour towards flagging solutions.

This user -> looneyd_noob is out of competition for the solution: https://codeforces.net/contest/1974/submission/261894175 but i also noticed the solution of this user -> Shaxx19 who is not out of the solution even having a very similar solution just variable name changed and some comments added and even submitted 10 minutes later; this is his solution https://codeforces.net/contest/1974/submission/261900757 the entire nested for loop is same with same indentation. Man he needs to get out of contest, you are doing very wrong and people's trust will reduce from this platform. Please get him out of competition.

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

    I noticed that someone has raised concerns regarding the similarity between my solution and another user's solution, and is requesting my disqualification from the competition.

    I would like to clarify that my solution is indeed my own work. Any similarities to other submissions are purely coincidental, as the nature of coding often leads to similar logic and structures when solving the same problem. I have added proper comments to demonstrate my understanding of the code, which the other user hadn't.

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

      bro there is no body coding and naming names likes this , offldfjsdlfj

      it s very obvious that u sent ur solution to that guy and he made some modfication too avoid getting kicked out

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

Can anyone tell me, what's wrong in my submission of Que (E) {https://codeforces.net/contest/1974/submission/262210794}

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

F was a simple binary search problem if you are aware of 2D coordinates to 1D conversion trick.Submission

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

Are there any good problems similar to this round C problem. I felt this is very unconventional in recent times

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

Task F huge plus plus Mann

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

Could anyone explain me how to implement Problem G using segment trees? I did'nt understand that part in the editorial

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

My code for Q.C is failing on testcase 7 can anyone tell why:

#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <cmath>
#include <unordered_map>
#include <cctype>
#include <algorithm>

using namespace std;
#define ll long long int

int main(){
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i=0; i<n; i++) cin >> a[i];
        ll ans = 0;
        for(int j=0; j<3; j++){
            map<pair<int,int>, vector<int>> check;
            for(int i=0; i<n-2; i++){
                if(j == 0){
                    check[{a[i+1], a[i+2]}].push_back(a[i]);
                }else if(j == 1){
                    check[{a[i], a[i+2]}].push_back(a[i+1]);
                }else{
                    check[{a[i], a[i+1]}].push_back(a[i+2]);
                }
            }
            for(auto x:check){
                int count = 1;
                vector<ll> count_push;
                sort(x.second.begin(), x.second.end());
                for(int i=1; i<x.second.size(); i++){
                    if(x.second[i-1] == x.second[i]){
                        count++;
                    }else{
                        count_push.push_back(count);
                        count = 1;
                    }
                }
                count_push.push_back(count);
                ll val = accumulate(count_push.begin(), count_push.end(), 0LL);
                for(auto y:count_push){
                    ans -= y*(y-1)/2;
                }
                ans += (x.second.size()*(x.second.size()-1))/2;
            }
        }
        cout << ans << "\n";
    }
}
»
5 недель назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

why could my knapsack solution be failing on E? My solution

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

Can someone write a solution in C++ for Qo C There is no suitable hash function in unordered map for a tuple in C++ !

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

    You can just use vector instead tuple and it will work without coding a hash function. In fact you can just use a pair for this problem so it exists a hash function in the STL :)

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

solution of c blowed my mind ,,never though of using map this way

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

What will your expression after finding wrong answer on 1601th line of problem A?

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

isn't the time complexity of solution of f given is O(m*n) ?

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

can anyone help me in writing the recursive dp code for the problem E? its similar to knapsack 2 of atcoder but the thing that is troubling me is in knapsack problem we have a constant capacity w but here w is the salary that is getting changed continously.So, unable to handle it. any kind of help is welcomed.

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

In the fifth question, I have implemented a somewhat different dynamic programming technique than suggested using an unordered_map and set. I have iterated through months 1 to n and during each iteration, I have updated the dp table using the following idea: Define following variables:
money: Total amount earned till that month (m-1)*x
k: happiness obtained at a cost of less than or equals to money
spent: the amount spent in obtaining a hapiness of k
Now, if cost[i]<money,
define k1: (happiness obtained in ith month) + (maximum happiness obtained at a cost of less than or equals to money- cost[i])
if(k1>k), we update spent to cost[i] + money spent in obtaining (maximum happiness obtained at a cost of less than or equals to money- cost[i]), and update dp[spent]=max(k,k1).
Now to locate the indices in the dp table, we can store the spent values in a set and use the lower_bound() function. Since lower bound function returns the minimum value in the set greater than equals to, and we need a spent index less than equals to some integer, the spent values can be stored in the set after multiplying with -1.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mod=1000000007;

void solve(){
    int m,x;
    cin>>m>>x;
    vector<int> cost(m,0),hap(m,0);
    for(int i=0;i<m;i++){
        cin>>cost[i]>>hap[i];
    }
    unordered_map<int,int> mp;
    mp[0]=0;
    set<int> s;
    s.insert(0);
    for(int i=0;i<m;i++){
        int money=x*i;
        int k=mp[-1*(*s.lower_bound(-1*money))];
        int spent=-1*(*s.lower_bound(-1*money));
        if(cost[i]<=money){
            int k1=hap[i]+mp[-1*(*s.lower_bound(-1*(money-cost[i])))];
            if(k1>k){
                spent=-1*(*s.lower_bound(-1*(money-cost[i])))+cost[i];
            }
            k=max(k,k1);
        }
        mp[spent]=k;
        s.insert(-1*spent);
    }
    cout<<mp[-1*(*s.lower_bound(-1*(x*(m-1))))]<<endl;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int t=1;
    cin>>t;
    while(t>0){
        solve();
        t--;
    }
}

265689316

This is failing in some 104th case of test-2. What can be the mistake in my approach ?

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

Can anyone help me why the solution 265737031 is giving a wrong answer on test 2, subtest case number 1504, any help is appreciated. Thank you. :)

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

OG problems!!

»
29 часов назад, # |
Rev. 2   Проголосовать: нравится -12 Проголосовать: не нравится

PLEASE Help me in submitting my solution in C problem[problem:1974C]. I am following the same approach as many have done in their solutions, which might be the only way to solve the problem. I am just creating a map to store all the triplets in form of a string, just with a slight change that where I get bi not equal to ci I am putting '0' instead of it. Here's the link to my submission: submission Please have a look Vladosiya.