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

Автор errorgorn, история, 5 лет назад, По-английски

1526A - Среднее неравенство...

Setter: antontrygubO_o
Preparer: errorgorn

Hint 1
Hint 2
Solution
Code (C++)
Code (Python)

1526B - Я ненавижу 1111

Setter: errorgorn
Preparer: errorgorn

Hint 0
Hint 1
Hint 2
Solution
Code (C++)
Code (Python)

1526C1 - Настойки (простая версия) and 1526C2 - Настойки (сложная версия)

Setter: errorgorn and oolimry
Preparer: oolimry

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
Code 2 (C++)
Code (Python)

1526D - Убить Антона

Setter: errorgorn
Preparer: errorgorn

Hint 1
Solution
Code (C++)
Code (Python)

1526E - Oolimry и суффиксный массив

Setter: iLoveIOI
Preparer: iLoveIOI

Hint 1
Solution
Code (C++)
Code (Python)

1526F - Запросы медианы

Setter: errorgorn and oolimry
Preparer: errorgorn

Hint 1
Hint 2
Solution
Code (C++)
Code (Python)

Code Golf

You may have realized that python codes in the editorial are quite short. We actually had a code golf challenge among testers. You are invited to try code golf our problems and put them in the comments. Maybe I will put the shortest codes in the editorial ;)

Rules for code golf:

  • any language allowed
  • codes will be judged by number of characters
  • must get AC in the respective problems
Разбор задач Codeforces Round 723 (Div. 2)
  • Проголосовать: нравится
  • +199
  • Проголосовать: не нравится

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

ERRORGORN OFZ

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

I wish they were BUGABOO's so that I can solve them.

QUESTIONS are really hard to ANSWER :")

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

When the problemsetters have plans for the night: lol
Source: 1526B - I Hate 1111

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

speedforces :)

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

I seriously hate 1111 after this contest.

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

Did not see solution to A.

Edit: Which is a shame because I solved B and and both C correctly.

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

    You could random shuffle the array until it becomes good. Though it makes the code longer (not that much longer), it's a nice alternative to the proposed solution.

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

      Actually I thought about that, but was not able to aproximate the probability that it works.

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

      It is going to take a lot of time.

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

        Let the number of all permutation of the 2*n elements be p=50!, without the rotations counted double it is p=49!

        So, how much of these p permutations qualify as "no solution" in the worst case? What is the expected number of shuffles until we find a good solution?

        It seems obvious that we got the most "no solution" permutations if the array is an arithmetic sequence, so WLG lets assume it is 1,2,3...,n

        Consider the third element, it must not be one of n-2, because all other of the n-2 elements produce a good solution. Same for the next element... and so on.

        So one aproximation to get a good perm looks like $$$(n-2)/(n-1) * (n-3)/(n-2) * (n-4)/(n-3) * ... $$$

        This formular is a of course a simplyfication and kind of simply wrong, however, it yields an propabilty of ~0.04, ie an expected value of ~25 shuffles until we find a good permutation.

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

    You could have solved A later and maybe then you would have got the idea. I usually solve problems in order, but I was not sure of my solution to A (though it was right), then moved to B which again I failed to solve. I opened C1,C2 and was able to solve them fast. Then returned to A and then to B.

    In A i sorted the elements first say for example 1 2 3 4 5 6 and arranged them like 1 6 2 5 3 4.

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

      Well, I've gotten used to thinking twice before submitting the first time.

      When I cannot solve A this means at some point of time I solved B, then have to decide, do I really want to participate with this? I am late, I have no solution to A.

      Most likely the answer is simply no, at least for me. In this contest, it turns out I would have had a positive delta even without solving A. But that is usually not the case.

      I would have to overcome this "rating-thinking", which would actually be good on a rational level, because it really doesn't matter whether I'm 1500 or 1600. But the point is still difficult for me.

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

        It does feels bad when i lose rating but i don't skip if i don't get any solution for 40 minutes (happened in this contest). As long as we don't cross our highest rating, any rating below it will be temporary.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +98 Проголосовать: не нравится
All numbers other than 11 and 111 are useless.

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

despite bricking the round, i enjoyed it. thanks for the amazing round!

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

Thanks the authurs for nice bugaboos statements and detail + quick solutions for those bugaboos

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

i've never seen so many memes in 1 editorial

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

i know everyone will downvote this but problem 2 is such a bad problem. CP problems should never be based one single tricky clue

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

Please someone explain why in 2nd problem only 11 and 111 are useful. Thanks :|

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

    you can express 11111 as 111*100 +11 and 1111 as 11 * 100 +11 and use a similar argument for all other numbers of the sort

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

    let's call k times 1 as k-1. So 4-1, 6-1 and 8-1 could be made just by 2-11(1100 + 11, 110000 + 1100 + 11, 11000000 + 110000 + 1100 + 11). Further 5-1 and 7-1 can be made by 2-1 and 3-1 alone(11100 + 11, 1110000 + 1100 + 11) so instead of using 4-1, 5-1, 6-1, 7-1, 8-1 we can simply use 2-1 and 3-1 so we can ignore everything except 2-1 and 3-1.

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

will this be the fastest editorial of all time?

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

So we can just brute force all 11 value of D to check whether X can be made. but we would still have to find A and C to satisfy equation ?

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

I used random shuffle until the array is good :( (problem A)

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

Pls tell me how to improve my skills! I couldn't solve any problems in this contest. :(

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

How in problem C1, the dp does not depend upon the actual potions taken? I mean, how can I calculate ans for dp[i][k] without knowing what is my current health?

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

Well put-together editorial!

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

Thanks for B.

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

Can anybody explain what is wrong in my solution for problem C1 div2(https://mirror.codeforces.com/contest/1526/submission/117651697)

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

    Consider a multiset of integers: { 1 , 1 , 2 , 3 , 4 }

    When you write this line : a.erase(*a.begin()); // or try to erase any occurrence of an element

    Spoiler
    Solution

    I hope you understand this simple issue with your code.

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

Vote if you hate 1111 too :(

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

Weird Idea for Problem A

Though the idea is not good, we can random_shuffle() the whole array for infinity times and check if it satisfies the condition at any moment.

(In this way, my problem A got accepted)

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

C1 was easier than B for me even though I wasn't able to solve both

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

I tried Top Down DP approach for C1. Potions (Easy Version) but I got TLE on pretest-3. Here is my code. Can you tell me why I got TLE for this and what should be the optimal Top-Down DP Solution for the same?

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
 
vector<ll> v;
ll n;
map<pair<ll,ll>,ll> dp;
ll fun(ll i,ll cur)
{
    if(i>n or cur<0) return 0;
    if(i==n) return cur>=0;
    if(dp.find({i,cur})!=dp.end()) return dp[{i,cur}];
    ll ans=fun(i+1,cur);
    if((cur+v[i]) >=0) ans=max(fun(i+1,cur+v[i])+1,fun(i+1,cur));
    return dp[{i,cur}]=ans;
}
 
int main() {
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(ll i=0;i<n;i++)
	{
	    ll x;
	    cin>>x;
	    v.push_back(x);
	}
	cout<<max(fun(0,0)-1,0ll);
	return 0;
}

Thanks in Advance :)

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

For B, what about this simpler solution:

Consider $$$x=n \mod 11$$$ We need to use at least x times 111, so if $$$n \gt =111*x$$$ then there is a solution since $$$n-x*111=0 \mod 11$$$, else there is none.

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

Alternate solution to A: You can just sort the array and swap all elements by 1 on right except first and last elements

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

Oh no

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

You can drink Potion with 0, right? but the ans is not according to that, what's wrong in this code

int main() {
	int n;cin>>n;
	vector<int> v(n);
	vector<int> ne;
	int ans=0;
	int count = 0;
	for(int i=0;i<n;i++){
		cin>>v[i];
		if(v[i]>=0){
		count+=v[i];
		ans++;
		}
		else
		ne.push_back(-1*v[i]);
	}
	sort(ne.begin(),ne.end());
	int len = ne.size();
	for(int i=0;i<len;i++){
		count -=ne[i];
		if(count>=0){
			ans++;
		}else{
			break;
		}
	}
	cout<<ans<<endl;
  return 0;
}
  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Your solution is wrong. You are adding all the negative values at the end, which is not what the question is asking for.

    For example, for the case

    1 -2 1000

    if you add positives and then subtract negatives you will get 3 as the answer. However, we cannot take -2, since that would decrease your running total to -1, which is not allowed.

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

What is the base case for 1526C1, (Method 1)DP solution? Also, shouldn't k increase, if we are counting how many potions are we taking?

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

Love the way "You write editorial".

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

Problem D, I used cin, cout, unordered_map to solve and get TLE, change these to scanf, prinf and character to number and unordered_map to array and got AC.

Poor me!

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

wtf is Chicken McNugget and why on earth should one even know this sht????

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

In question C, why using upper_bound in multiset while substituting the ith number gives wrong answer but removing the last element does the trick?

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

How to solve C using dp ,please explain.

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

    say dp[i][j] means max HP after reaching i_th glass and having drunk j health potions. For the transition we can say that dp[i][j] = max(dp[i-1][j](meaning we did not drink the i_th potion), dp[i-1][j-1]+a[i](meaning we did drink the i_th potion)). For base case dp[-1][-1] = 0.(Take care of the indexing :))))

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

      Aren't we trying to maximize the number of potions we take, So in the dp why did we take dp[i][j] to be maximum health?

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

        yeah, see the answer will be the max j for which dp[n-1][j] is non negative. We are trying to keep the track of max health that we can have after being on i_th potion and having drunk j potions. The reason for that is that in future we might have to drink potions that'll decrease the character's health and so it should be as high as possible right now to be able to drink those negative potions while remaining alive.

»
5 лет назад, скрыть # |
Rev. 11  
Проголосовать: нравится -31 Проголосовать: не нравится

Easiest Solution.

Explanation: all the numbers 1111,11111,111111..... can be written as x*11+y*111 where x,y are non-negative integers.
So the only numbers we have to bother are 11,111.
Therefore we have to check if the given number can be written as a*11+b*111 where a,b are non-negative integers.
Spoiler

`[contest:723][problem:B]

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

Problem B can be solved in a much simpler way, the given number (say x) will be of the form x = a1 * 11 + a2 * 111 since, 111 can be written as 11*10 + 1, we can obtain the value of a2 as, a2 = x % 11

Then we can check if x - a2*111 is non-negative and divisible by 11.

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

Anton lived today, but I'll get him next time for sure.

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

Thanks for providing method 2 with Chicken McNugget Theorem in solution B.

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

I used multiset in C1 and C2 instead of priority queue

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

I have some questions regarding the proof of D.

  1. What is D1 and D2 ?
  1. Could you pls elaborate the equation and the next line "upto a contradiction"
»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think my solution on D should give TLE, but i can't prove it.

In my code, i did a 4! * (2^3) * N log N solution, and in first time i got TLE on pretest 5 . Basically the solution was: For any permutation of the 4 letters, try to rearrange the string by put the same letter together on the left or right side (well, that's not necessary cause im trying all the permutations, but i didnt realize) and then use FenwickTree to count inversion (same solution of editorial, but with *8 because of bitmask).

To avoid TLE i used a set that checks if the initially string miss some letter, in that case, i can avoid use some permutations. By doing that, i think the constant factor (4! * (2^3)) was reduced a little, but i think too that maybe in any worst case it shouldn't change. It passed from TLE on pretest5 to accepted with 970ms.

If anyone can find a case, or prove why using the set improves the code, it would be cool. Thanks.

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

memesforces.

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

Can anyone provide code/ intuition for the Merge Sort approach for bugaboo D?

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

    I didn't solved because I didn't notice that there were only 4 characters , :( . But I had the intuition , see I observed that all the elements will be together by righting a few things down and verifying with sample test cases , then I thought there were 26! Permutation ( as I didn't read 4 chars , :( ) . So now if you would look at that there are just 24 permutations and for sure the solution will be one of those permutation , then for the merge sort technique it is a well known idea of that number of inversion = minimum no. Of adjacent swaps , and it could be solved using PBDS and Merge sort .

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

    The whole idea is that that it is a number of inversions, after that you just calculate inversions using mergesort, a standard trick.

    You can look at my submission (yeah, I just copy-pasted merge sort from the internet if anything)

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

I think I don't understand why greedy for C2 works. I wonder can it not happen that one swap with the minimum in priority queue is not enough and we might need two swaps? Sure, it will decrease the number of potions for now, but it might happen that the potentially more positive value gained will help us take more negative potions in the future or something like that? And i am only talking about the case when after one swap our sum remained < 0, but after two swaps the sum became >= 0.

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

    If the current element is -11 and you had -10 before as most negative element , then you will not remover , but if you had -11 before and now the current element is -10 then deleting -11 is enough you don't need to delete any more.

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

      No I mean, if let's say our priority queue contains -7 and -5 . I just came across -11 and I can't take it as my sum becomes less than 0, so I check sum + 7 — 11 and it is negative still but if I also take 5, then it becomes sum + 7 + 5 — 11 which somehow comes out to be >= 0 , then isn't it optimal to remove both -7 and -5 and take the 11? Sure, the number of potions decreased but since our sum is now greater than earlier value and greater than 0, we might able to take more potions later on. Did I miss something? EDIT: I understood . Thanks :)

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

Can someone explain question B in very simple language to someone who suck at Cp..

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

In the potions problem, why do we keep the number of potions taken till now as one of the states? I mean that is something that we need to calcuate right? Why do we include it in the states?

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

Problem C1 easy version: how ro solve this provlem using 1D dp

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

    dp[i] = maximum health you can have with drinking exactly i potions in this level.

    for i : 1 -> n: potions

    for j : n -> 1:     number of potions we want to drink
    
         if(dp[j - 1] + a[i] >= 0) 
    
              dp[j] = max(dp[j], dp[j - 1] + a[i])

    Answer is the largest i, that we have a valid value for dp[i]

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

      Can you explain a bit more why are you defining dp[i] as the "Maximum Health"?

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

        Dp from editorial: "Let dp[i][k] be the maximum possible health achievable if we consider only the first i potions, and k is the total number of potions taken."

        Just like what editorial have explained, but we wanna remove the part of "if we consider only the first i potions" and we will only have dp[k]. So now dp[i] = maximum health that can be achieved by taking i potions in this level (we will iterate over array of potions and "level" will be that). The only thing is we need to iterate over number of potions we wanna take form n to 1, since we need to update our dp from last level, so that if we are updating dp[i], we need dp[j] (for all j < i) to be just like the last level and haven't been updated yet.

        submission.

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

segment tree in Div2 C seriously?

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

For problem C2 "Method 2 — Greedy 1" can be implemented without a lazy segment tree using BIT:
Maintain a set of positive potion positions, and a priority queue of {negative potion value, index}. Check if the negative potion can be consumed using BIT. Greedily start decrementing the potion value of positions in descending order of positions that are less than the index while exhausting the priority queue & remove the position from the set if potion value reaches zero.

UPD: It turns out that my previous submission (without BIT) gives TLE for this hack case since my worst-case time complexity was $$$\mathcal{O}(n^2\log{}n)$$$, after optimizing using BIT it reduces to $$$\mathcal{O}(n\log{}n)$$$.
Cheese submission: 117672658, Optimized submission: 117983932

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

There is a little difference of alphabet between D and editorial. It looks like DNAs initially and you modified it for your outstanding coordinator.

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

smallest and lovely solution for I Hate 1111 can be:-

as we know we have to check only for 11, 111 (from editorial),

  • if we can represent x = a*11 + b*111 (where b is as low as possible), we return true
  • else, we return false

And also 111 = 11*10 + 1, therefore equation reduces to x = (a+10*b)*11 + b

now b = x%11 and a + 10*b = x/11

  • so if the above conditions match we output true,
  • else false.

The neat sol. can be found at :- https://mirror.codeforces.com/contest/1526/submission/117617666

Hope it helps ;)

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

Is the name Anton came from Silicon Valley series?

 Silicon Valley

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

Can someone explain how they got the intuition for placing the same letters together in D?

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

Problem B was really nice and loved the editorial and the way solutions are given to the problems. Kudos to writers and testers!!

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

I loved I Hate 1111

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

what if in problem B there are 3 numbers left 11a+111b+(s)c=x how will we find if x can be made by adding any number of these 3 numbers 11,111,s ?

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

I have another visual proof of the Chicken McNugget theorem (from problem B)

n = 5 and m = 7, so it can get all the numbers after 5*7-5-7 = 23

Here is the number line of 5's  Then, here's the multiples of 7 lined up with it  You shift the marks of 7's by 5, which represent the multiples of 7 after 5 was added to them. Then you shift them again, which represent the multiples of 7 after 2*5 was added to them. (the red are the oranges shifted by 5 once, green are shifted by 5 twice)  For the formula of 5*7-7-5, when you subtract 7 from 35, you get to the last orange mark, which is 28. When you subtract 5 from 28 you get the last empty mark. 28 is the last distinct mark (has a position of 3 while others have positions 1, 2, and 4) that you need to get all the numbers, as you can see from the picture. If you ignore the colors you see the positions between the multiples of 5 slowly fill up.

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

Can anybody explain what is wrong in my solution for problem C2? First step I choose all positive number and calculate the sum of them. Second step I use priority_queue to find the minimum negative number, considering the sum and the sum of prefix of positives . Third I use BIT to substract the negative number I choose Here is my code:

Your text to link here...

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

Can anyone share DP solution for problem 3?

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

Code Golf for Question B 117721466

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

why tag dp for problem B ? is there a dp soln too?

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

//PROBLEM C EASY VERSION

//GOT TLE USING MAP **** //USE MAP BECAUSE I WANT TO STORE ARRAY ELEMENTS WHICH IS NOT POSSIBLE IN 2D DP

map<pair<int, int>, int> dp;

//USE MAP PAIR FOR INDEX AND SUM OF ELEMENTS OF ARRAY

// AND STORE THE COUNT OF POTIONS

int helper(int arr[], int i, int sum,int cnt,int n){

if(i == n){

    return cnt;

}

if(dp.find({i,sum}) != dp.end()){

    return dp[{i,sum}];

}
if((sum + arr[i]) < 0){

    return helper(arr,i+1,sum,cnt,n);
}

**//I USE KNAPSACK PROBLEM TO CHECK**
    **//IF I INCLUDE I INCREASE THE COUNT OF POTION**
**//AND RETURN THE MAXIMUM COUNT**


  //IN INCLUDE I SUM THE POTION AND INCREASE THE COUNT

int inc = helper(arr, i+1, sum + arr[i], cnt+1,n);

 //IN EXCLUDE I DO NOTHING PASS SAME

int exc = helper(arr, i+1,sum, cnt,n);

return dp[{i,sum}] = max(inc,exc);

} void solve(){ int n; cin >> n;

int arr[n];

for(int i = 0;i < n; i++)cin>>arr[i];

cout<<helper(arr, 0, 0, 0,n);

} signed main(){

solve();

}

//PLEASE HELP TO OPTIMIZE THIS CODE USING TOP DOWN DP **** //THEN I TRY THIS SOLUTION BY BUT THIS GIVES WRONG ANSWER **** // I DON'T KNOW HOW TO STORE LARGE VALUES IN 2D DP ****

int dp[2001][2001];

int helper(int arr[], int i, int sum,int cnt,int n){

if(i == n){
    return cnt;
}


if(dp[i][sum] != -1){

    return dp[i][sum];
}

if((sum + arr[i]) < 0){

    return helper(arr,i+1,sum,cnt,n);

}
int inc = helper(arr, i+1, sum + arr[i], cnt+1,n);

int exc = helper(arr, i+1,sum, cnt,n);

return dp[i][sum] = max(inc,exc);

} void solve(){

r(n);
memset(dp,-1,sizeof(dp));

int arr[n];

for(int i = 0;i < n; i++)cin>>arr[i];

cout<<helper(arr, 0, 0, 0,n);

} signed main(){

fast; 

solve();

// r(t); while(t--){    solve();nl;}

}

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

after reading each problem in this round i felt like "no one come up with this problem before, really?", especially for problem E

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

    it's not a good or bad, it's just a fact :)

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

      yea the way i usually set problems is taking existing problems and twisting them.

      B: I looked at 1517A - Sum of 2050 and wondered what happens if instead of $$$2050, 20500,\ldots$$$ we have $$$2050,20502050,\ldots$$$ instead.

      D: The problem of minimal number of swaps is well known, so I wondered can be find a string that maximizes the number of swaps.

      F: I think there are probably a few interactives with queries such as $$$|p[a]-p[b]|$$$, so I tried to make it annoying with median of $$$\{|p[a]-p[b]|,|p[b]-p[c]|,|p[a]-p[c]|\}$$$. But the turns out the solution was quite interesting.

      It's crazy how difficult you can make a problem become after just a tiny change. Like one of my favourite examples is AGC51_F. I think most people might know about telling the time using two sandglasses with integer times, but I think only someone amazing like rng_58 would dare to ask what happens if one of them have a irrational time.

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

Problem B be like: Read the name of the problem ;) Sometimes, Name also tells the intuition behind the problem. ;)

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

Another approach for B, as 111=11*10+1

if the below condition satisfies, its YES

11*a+1*b=n and a>=b*10;

code : https://mirror.codeforces.com/contest/1526/submission/117686801

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

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

where σ(x)={1,if x>0 −1,if x<0, or rather σ is the sign function. Can anyone explain me the meaning of these symbols used in D problem

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

For Problem 1526C1, Method 2 — Greedy 1

In the editorial, we have —

We iterate through the potions in non-decreasing order and drink the potion if we do not die.

Shouldn't it be non-increasing order?

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

Can anyone tell why problemset name is changed to bugabooset?

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

I am confused on C problem on test case #2.There is array of numbers -3 -3 -7 -7 -1 -7 3 3 -2 -1 0 -7. Well, if you choose -1,3,3,-2,-1 and 0, it will be non-negative result, hence the maximum number you can pick is six. Why they state in solution that the answer is five, if obviously I have proved that you can pick six of them?

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

What is WLOG here, in the proof of D.

Since D1+D2≥0, either D1≥0 or D2≥0. WLOG, D1≥0.

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

Sorry...

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

How are the D1 and D2 written in the editorial of problem D? I am not getting the intuition that letters should be grouped together :( Or maybe someone can explain clearly how they come up with the intuition of grouping letters together? NVM GOT IT :)

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

1526B - I Hate 1111 Can someone give the solution code using method 1 in the B problem?

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

I think there is a typo in Problem E's editorial. "Now, this becomes count how many arrays of $$$(n-1+2)=(n+1)$$$ non-negative elements sum to $$$k-cnt$$$." This should be "sum to $$$k-cnt-1$$$".

Therefore final answer should be $$$ C_{n+1-1}^{n+1+k-cnt-1-1}$$$ i.e. $$$C_n^{n-1+k-cnt}$$$

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

It's tough for me to come up with the proof of the Greedy solution of C on my own, and also, I find it very difficult to understand the proof of greedy solution of C.Any help, how can I get over this? Usually, I cannot prove my solutions clearly (It usually gets unorganised, I don't know how). Any specific advice which will help me?

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

can someone please give a easy mathematical proof for problem d.For me the proof given is a bit difficult to understand.

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

    Let s be the original string and t be the optimal ans string so that the number of moves to convert t into s is maximum.

    So, how do we calculate the number of moves? Basically we go on moving from left to right reading each character of si one by one , find the earliest occurence of this character in the substring t[i..n-1] and then do the swap and appropriate value to our no. of moves.

    Let us assume we are currently reading the character at ith pos which is x. Also let j be the next pos where x ocuurs. So we have something like .........x????????????x????????? where ? can be any valid character other than x and '.' means we have already settled that position with appropriate character. Lets also assume that now t something looks like ..........???????x???????x???????. As you can clearly see as we move x by one our ans also increase by 1 and hence it is always optimal to club all the x's to the rightmost x in our suboptimal ans string.

    Codeforces-Round-723-Div-2-Editorial-Codeforces-Google-Chrome-30-05-2021-19-18-51-2

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

Code Can anyone help me with problem D Kill Anton? Here, I have tried to calculate the number of inversions by segment tree. I have solved 1430E-String Reversal using the same segment tree method for calculating the number of inversions, and here is my submission for that. I couldn't figure out what mistake I am making here. Here is my Code for Kill Anton.

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

Can C1. Potions (Easy Version) be solved using Top-Down DP?

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

Anyone who understood C2 using DP / SegTree given in editorial ? .... , It will be great help if it can explained in simpler words...Anyone?

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

aaaaa I'm fukn stupid. for problem F, I didn't realize that if there was a tie for the furthest $$$x$$$, you could simply choose any one of them.

Instead, I did the following. Consider the four numbers $$$x, y, z, w$$$. Suppose $$$x$$$ and $$$y$$$ are tied for furthest, and $$$z$$$ and $$$w$$$ are tied for second-furthest. We can repeat the same queries on those numbers using $$$(b, c)$$$ and $$$(a, c)$$$ instead of $$$(a, b)$$$. Out of those, it's guaranteed that one of them won't produce a tie for the furthest number.

needed hint 1 and a full day in order to upsolve, my brain is melted now tho :)

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

I have O(1) general solution for problem B (div2). Please find submission at: https://mirror.codeforces.com/contest/1526/submission/118087579

I have tried to capture the logic in the image attached. Here

Please let me know if you find error in the solution. Thanks!!

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

Hi! can someone please explain the logic of problem D, please? I'm not able to approach the problem right.

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

what is the intuition behind problem D's solution or how did people came up their idea ?

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

In Problem C Method-3
I get the solution that replacing the most negative element in the priority queue with less negative yields an optimal solution. But, I don't understand what are they trying to prove later in the explanation. In short, I don't understand the proof and also I very badly want to know that as It will help me proving other things better and also I will enjoy the proof. So, please anyone explain to me the proof that is mentioned there. Your efforts will be highly appreciated.

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

potions easyversion....dp method...isnt it wrong?...we need the max potions possible

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

Excuse me, why we can say |y2-a|<=|a-1| in Proof 4, Problem F? As we have no idea how large "a" exactly is. What if "a" were too large? Thanks for anyone's help! Noted that "pa<pb<pc" was our assumption, so there's not a range for "a", in my opinion.

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

can anyone explain c2 greedy 1 solution. i couldnt understand the editorial

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

why sorting (in decending) not working in problem C.

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

In the solution for problem E, the last step is calculating screenshot

However, in the solution(python), it says k-cnt+n-1 choose n

My result is also n+k-cnt-1, and my submission is accepted https://mirror.codeforces.com/contest/1526/submission/122438057

Is there a typo, or I missed something?

Thank you!

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

The official solution for F is unnecessarily complicated. A far simpler deterministic solution (in terms of the high level idea, not the involved casework) that takes at most $$$2 \cdot n + 3$$$ queries exists.

TLDR;

Find $$$p_2 - p_1$$$ in $$$n$$$ queries. Handle the case where $$$p_2 - p_1 = 1$$$ separately. Find all the values between $$$p_1$$$ and $$$p_2$$$ using one query per element. Then use $$$p_1$$$ and $$$p_x$$$ (where $$$p_x = p_1 + 1$$$) to disambiguate the values of all other elements.

Code: 362638073

I'll provide a brief outline below, but most proofs and casework are left as an exercise to the reader (I don't wanna go insane).

Denote $$$q(a, b, c)$$$ to be the result of a query on $$$(a, b, c)$$$. We will assume $$$n \geq 20$$$.

First, query $$$r_i = q(1, 2, i)$$$ for all $$$i$$$ (assume $$$r_1$$$ and $$$r_2$$$ to be undefined).

Some lemmas:

  1. At most one value can occur in $$$r$$$ more than twice.
  2. If some value $$$x$$$ occurs more than twice in $$$r$$$, then $$$p_2 - p_1 = x$$$.

We now consider three cases:

  1. All $$$r_i$$$ are unique: This implies that either $$$p_1 = 1, p_2 = 2$$$, or $$$p_1 = n - 1, p_2 = n$$$. It's easy to determine which one of these is the case, by comparing $$$q(x, y, 2)$$$ and $$$q(x, y, 1)$$$, where $$$x$$$ is the unique index for which $$$r_x = 1$$$, and $$$y$$$ is the unique index for which $$$r_y = 2$$$. If we have $$$p_1 = 1, p_2 = 2$$$, then $$$p_i = 2 + r_i$$$, and otherwise, $$$p_i = n - 1 - r_i$$$.
  2. No value occurs thrice in $$$r$$$, and $$$1$$$ occurs exactly twice in $$$r$$$: One can show that in this case, $$$p_2 = p_1 + 1$$$. We can find all $$$q(i, x, y)$$$ where $$$i \in \lbrace 1, 2 \rbrace, r_x = 1, r_y = 2$$$ (at most 8 such combinations), and then do casework over these values to find $$$x$$$ such that $$$p_x = p_1 - 1$$$. Once we have this $$$x$$$, we can uniquely determine $$$p_i$$$ for all $$$i$$$, using just $$$q(1, x, i)$$$ and $$$r_i$$$.
  3. Everything else: We will now have $$$p_2 - p_1 \gt 1$$$.
    • Notice that $$$p_1 \lt p_x \lt p_2 \iff r_x \lt p_2 - p_1$$$.
    • Also Notice that we can determine $$$p_2 - p_1$$$ using $$$\min_{i \gt 2} r_i$$$ (these minimums correspond to the middle elements on the range $$$[p_1, p_2]$$$).
    • If there are two middle elements (when $$$p_2 - p_1$$$ is odd), we can do some extremely annoying casework to determine which one of the two is to the left.
    • Let $$$m$$$ be the unique/left middle element. For all elements $$$y$$$ with $$$r_y \lt p_2 - p_1$$$ except the middle(s), we compare $$$r_y$$$ with $$$q(1, m, y)$$$ to uniquely determine their value.
    • We will now have some unique $$$x$$$ such that $$$p_x = p_1 + 1$$$. For all elements with $$$r_y \geq p_2 - p_1$$$, we can compare $$$r_y$$$ with $$$q(1, y, x)$$$ to uniquely determine their value. There is an edge case here: we will have $$$r_y = q(1, y, x)$$$ for both $$$p_y = p_1 - (p_2 - p_1)$$$ and $$$p_y = p_2 + 1$$$, so we'll have to make one more query for these ($$$q(2, x, y)$$$ is enough to disambiguate).