Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Name |
---|
Great contest! Thank u!)
Why is this comment downvoted?
Green coder.
[Deleted]
Maybe the contest was too frustrating for the downvoters.
Great contest and great problems ! But weak test cases for problem A div1 ...
To make the hacks possible
Deleted
It's a good contest! I like these problems! Thank you:-)
Really weak pretests for Div2 C.
I don't know if i'm too weak or not, but to me this must have been the hardest round that I have participate in
You didn't paricipate ... Right? am i missing something?
i used another account
feel free to show us your resultus ^_^ for real ... no insult here
It was more mathematical skills and less programming skills.
same bruh only solved A that to very slow:(
Weak test data (pretests) for problem 'C' Div.2 or 'A' Div.1 made a lot of solutions (more than usual) get WA during system tests . I hope next round's test data will be much stronger . Anyway,it was a great round and I hope everyone got what they wanted :)
Can someone explain D, please? Can you prove why the claim: "the Young diagram can be partitioned into domino if and only if the number of white cells inside it is equal to the number of black cells inside it." is true? Also, why was the example of a "basic" diagram provided?
We know that every domino occupies one white cell and one black cell. Assume that we can cover all the screen if the number of white cells is not equal to the number of black cells. name the number of whites "a" and the number of blacks "b". Every white domino has a black side so all of the white dominoes have black dominoes ( For the other side of the domino). so we have b-a dominoes that both sides are black and that is a contradiction. Sorry for my poor English :)
Let me give it a shot!
Well, if you color it this way, you can see that each cell has adjacent cells only of a different color. Also, note that if we place a tile on the diagram, it will always cover 1 white ane 1 black square.
Now, let's say that the white squares are less than the black ones. We can see that if try an example!
So, if for example, the white squares are less than the black ones, it makes sense that if you try to connect them to blacks, we'll run out of white ones before blacks. So, intuitively the answer is $$$min(numOfBacks, numOfWhites)$$$!
If we use domino structure as given in image and keep it's both endpoints on the columns containing an odd number of lengths. now both endpoints require even number of the block left to be filled and middle columns are unaffected(on basis of parity).but the length of this structure should be even. this way we can joint at most min(columns with an odd block at odd indexes, columns with an odd block at even indexes) columns. ~~~~~
int tot = 0,odd = 0,even = 0; for(i=1;i<=n;i++) { tot+=a[i]/2; if(a[i]%2) { if(i%2) odd++; else even++; } } ans = tot + min(odd,even)
~~~~~IMAGE LINK — https://drive.google.com/open?id=1gSMW0RAXRMz8LtSVUREzNiI0lYAYfAHd
So, i am a newbie to giving contests. This was my 5th contest and i wasn't able to solve any one of them this time too. Is that normal and will i be able to become good at this anytime soon if i practice. I have been practicing a2oj ladders lately. Everyone's feedback and support is appreciated.
My only advice in this respect would be to try and solve most of the questions that you couldn't solve in this contest. If you can solve questions out of the contest, then atleast you will have something to do during the contest.
You may make simple targets like solving 1 or 2 in order of difficulty which you couldn't solve during the contest. :)
I'm new too and getting crushed in my first 4 contests. I solve mostly problem A in div 2, maybe B and I never have time to attempt C or harder problems.
If you look at the rating graphs of other users, even the top ones, they often have a dip (falling rating) in the beginning so I think it is normal.
You should participate in maximum contest and try to do questions after contest you couldn't solve and then analyse it why u couldn't solve them in contest.
As you can see my graph initially i solved 1-2 questions and i gradually improved these things requires patience.
For div2D, why doesn't this solution work?
We start from the first column and we move to the right. There are several cases:
I could not find any test cases that break this greedy. Can you help me? Thanks!
Here is my code: https://codeforces.net/contest/1269/submission/67367653
I was thinking something like that :(
Check this case:
8
7 6 5 4 4 3 2 1
The answer is 16.
Thanks for the test case! Now I can see why it doesn't work! :)
You should use long long int instead of int and then try again because in your code, you have used int and the answer in some cases may exceed the range of int. Hope, it helps.
Here is my code with long long: https://codeforces.net/contest/1269/submission/67371998
It still fails, because the greedy I described is wrong.
Problem A. I spent half an hour on you. Good round.Thank you 300iq!!!
Can someone hack my Div2C / Div1A or is it actually O(n) code?
Don't you think that samples in Div2A are a bit too suggestive xD?
Oh... You know, I had other answers in the "tests" test set. But then I copied that to "pretests" and forgot about it...
And right now I can't stop my laugh because I didn't even suspect that I have these answers XD
Can we solve Div2D using dp?
I don't think so.
Ok, Thanks!
I AC Div2D using a greedy approach, please tell me if it is wrong. Looping over pillars from left to right. For each pillar, try to place as many blocks vertically from top to down. If it have one space empty in the bottom, then we occupy this space greedily by placing a block horizontally. When processing pillars, if (len[i]-horizontal_height)%2==1, then increase horizontal blocks height by one, else decrease by one(it's pretty obvious if you draws it). If the horizontal blocks height is larger than maximum allowed height, then calculate how many space is wasted.
genius
What's len[i] here ??
$$$a_i$$$
Is Div1B Div2D editorial not completed?
No, its completed.
Then, something wrong with it:
First, it may have not equal number of white and black cells from beginning. Second, I think it should be stressed out that after deletion it is still Young diagram.
Where to look at? Should I look into other task editorial? I don't understand.
The algorithm is: find two equal rows or columns and delete domino on the.
For example, if you have
7 6 6 5 4 3
You can delete one domino, to get another young diagram.
7 5 5 5 4 3
I claim that editorial is incomplete. First quoted by me sentence is simply wrong if you don't say that number of black and white cells were equal.
Next, if you say "assume that number of black and white cells are equal" then later where you say "So we have a contradiction!" Contradiction with what? With equal number of black and white? Yes. In short: assume we have equal -> no, we don't! This is not connected to anything else.
You could say following: you can place one domino and unfilled cells would still have equal number of black and white cells. So, lets continue fill cells by domino like this until you can't. This means that there is no two equal rows or columns. Thus, we're left with 'basic' diagram. But in basic diagram number of black and white cells are not equal. Therefore we should fill everything using this algorithm.
In short, we showed that if we have equal number of black and white cells, then we can fill all cells by domino.
Now, about not equal:
You talk about case when no equal rows and columns. But what about case when there are equal rows and columns? I think you want just do the same algorithm until you have 'basic' diagram. But what if there is filling that is better because it does something different?
There is simple proof that you can't do better than minimum, but you didn't include it. As someone already noted in comments: no matter how you place domino, you always "use" single black and single white cell. So, you can't place more than $$$min(black, white)$$$. Then, it's easy to see that the same algorithm doesn't reduce this minimum, but in the end you have 'basic' diagram that can be processed as you said.
If you don't want complete editorial, then alright. I just don't like when missing parts of editorial is placed in comments.
The editorial does not need to have every detail in depth its just the general idea so you can get the details yourself.
At least I would require editorial to be coherent. I mean, it should have narative order.
But, let me just disagree with you. And I'll also tell why.
Task solutions should be proven. Otherwise, we can't claim that there is no better output. In other words, task should be correct. Because if solution or checker is wrong, then how can you judge?
Now. Imagine there is no proof in editorial. Then, all we have to do is: prove it by yourselves, or simply belive that author has correct proof.
I was looking into editorial, because I was need a proof, and I had problems with mine. And, instead of connected proof I saw puzzle of sentences, and had to figure out what is related to what.
Yes, I was able to figure out, but only after reply with example what exactly means "remove domino".
And, in the end: I think, editorial should not have "simply wrong" statements, and also there should be no places where you should guess right meaning of what author wanted to say.
So, in short: I don't belive that problem is correct unless I have a proof. I don't require proofs of simple facts. But when fact is not simple, I would like to have detailed explanation. Simplicity of fact is based on difficulty to find proof, not by difficulty of fact or difficulty of proof. Fact can be simple, but proof can be hard. Fact and proof can be both simple, but if it's very hard to find a proof — it should be explained.
I find a test that I use author's algorithm is wrong: 16 2 2 1 2 1 2 2 2 2 1 1 1 1 1 2 1 If using author's algorithm, we will have 12 domino, it's mean we have to fill all cells, but how we fill the 15th and 16th col
This test is invalid. Sequence should be non increasing.
Oh !!! Sorry, my mistake
"Just because if you have more white cells (case with more black case is symmetrical), you can take the first column with more white cells than black cells and delete the last cell of this column" — I think it is not true if you have equal columns since resulting diagram can no longer be Young one. But if you preced that with argument of dealing with equal columns then you will be fine I think.
Oh, yes, of course.
Excuse me, there might be a small problem in the editorial of 1269E:
[After that, let's say that $$$x≤k$$$ is zero, and $$$x>k$$$ is one.]
[Then you need to calculate the smallest number of swaps to make segment $$$1,1,…,1$$$ of length $$$k$$$ appear in the permutation.]
Isn't it segment $$$0,0,...,0$$$ of length $$$k$$$? I'm confused.
UPD: Fixed.
Yes, indeed, sorry.
Can anyone explain me div2 D
can someone exlain me Div2B?
Basically we are first finding all the possible values of x for which elements in the array a can be converted totally into array b, We are doing this by comparing each element in array a with b1
For example
let m=5, a={4,2,3,2,1} and b={2,3,3,4,5}
so first comparing
a1 with b1 we get x=3,
a2 with b1 we get x=0,
a3 with b1 we get x=4,
a4 with b1 we get x=0,
a5 with b1 we get x=1,
then we can add each of these Xs to array a and check if we are getting array b or not, for all valid Xs , we store the minimum X
I did it using 2 loops(one for getting X and then temporarily increasing array a with x and comparing it with b) with O(n^2) and it passed the testcases
Thanks, how is it guaranteed that the value of X will be from one of these only and not anything else since we didn't consider b2, b3, b4... in this?
Think about it this way.. Suppose you know the correct X, then adding the X to the array A will result in ONE of the element of A to become equal to b1.
I mean for a correct X, a1 may become b1 or a2 may become b1 and so on.. I mean every element of A has chance to become b1.. So we can just compare all elements of A with b1, store all the values for which elements in A become b1.. For a correct X all elements in A will map to corresponding elements in B.
in div2 E what is "si"?
I think $$$s_i$$$ here represents the array formed after replacing x<=k by one and x>k by zero.
Then for $$$s_i$$$ = 0 means that it should not be present in the subsegment so minimum number of swaps required to remove it would be min($$$p_i$$$, k-$$$p_i$$$).
What was test case 7 for Div2C?
I believe it was larger version of:
9 3
123113133
Answer should be:
9
123123123
Correct me if i'm wrong
It kind of was...
actually there was a mistake in the part of code which compares numbers...
Thanks for helping!!!
What a coincidence! I made the same error and Maxymilian's test-case illuminated me. I won't forget you when I become a grandmaster. :)
Can someone explain div2 B to me , i didn't understand the editorial
Please see my reply below
Pls explain Div 2 B (with code if possible) I'm stuck:(
Hi, In this question, listA is at some distance from listB and author guarantee that there is a solution i,e if you will add some non-negative number X then listA will become listB. Also, this means every number of listA will map out to some number of B after addition of this number X. Now, let's take first element of A (i,e A[0]) and look for it's all possible distances from listB by iterating over elements of listB. One of this distance is definitely guaranteed to be X. So, just iterate over all possible distance and for each distance, calculate new listA (let's call it listA') and compare listA' and listB (by sorting). Finally, output minimum distance for which listA' is equal to listB. Submission Link
Hope this helps
unable to understand this part
why are we adding a +m before dividing by mod m?
To avoid negative difference. Adding modulus M doesn't affect the significance of the current difference. For example, number "-1" and "2" both are same number with respect to modulus 3. Make sense?
More explain on Div.2 problem E, please.
May be this will help: https://codeforces.net/blog/entry/72358?#comment-566415 I would like to see proof though, about independency of gathering and inversions.
Could you please explain to me the formula in Endagorion 67338561
Thank you, but why do we have
L * (L - 1) / 2
andR * (R + 1) / 2
here? In masalskyi's code (67434904), he has another way:He don't include mid for both of ranges.
Can anyone prove that editorial solution of div2C gives correct answer?
Yes, I can. Consider the set of all beautiful integers. For example, 123123123 can be written as (123)*(10**(0)+10**(3)+10**(6)) So any beautiful integer in general can be written as (a1a2a3..ak)*(sum of powers of 10). Now, the key thing to realise is if the number a1a2a3...ak is lesser than the first k digits of the input number x, then the beautiful integer of the same length so formed is definitely less than x. This can be easily shown.
Since we have to find y>=x, we start our search from the first k integers of x.
Note again that if a1a2a3...ak is greater than the first k digits of x, then the beautiful integer so formed is definitely greater than x. This can also be shown similarly and easily.
So we start our search from a1a2a3...ak, the first k integers of x. If the beautiful solution so formed is greater than or equal to x, we can print y. (We are sure that this is indeed the smallest, since any smaller and y definitely becomes less than x).
If y is smaller, we add 1 to the number a1a2...ak and print the beautiful integer so formed. This is definitely greater than x and no number smaller than this is greater than x. Hence proved.
If you have any doubt, feel free to post it.
Could anyone here help me figure out what's wrong with my solution for Div 2 (C)? I have tried to follow the editorial here.
Link.
for (int i = 1; i <= n; i++) if (num1[i] > num2[i]) flag++;
this part of the code is causing the error
run this testcase: 6 3 427129 your solution — 428428 but the correct ans 427427.
Yes, I figured it out. I was comparing the numbers stored in the arrays incorrectly.
This is not the correct way to check if num1 > num2. Thanks!
i think the word 'ciclycally' is a russian word. as a non-russian speaker, i find the use of the word confusing. you should have used a better word, such as 'cyclically.'
edit: the typo was fixed. i don't think my comment warrants such many downvotes, i was pointing out the typo in a somewhat sarcastic way.
that's not a Russian word, that's just a typo.
For Div2 C, we can take the first k digits as a number and repeat it for length n, and then add one to that number and repeat it again for length n . This is optimal and i know it works.
But i am unable to proof that why it'll always work, can anyone help me with a proof?
Make new number with first $$$k$$$ digits same as given number.
Firstly, check if new number ( with first $$$k$$$ repeated till $$$n$$$ ) is greater or equal to original number. If yes, then obviously print it.
If it is not greater, then increasing the number formed by the first $$$k$$$ digits by one is the smallest increase which enables you to have a number greater than the original, since now your number has first $$$x$$$ ( depending on number of $$$9$$$s at end of the first $$$k$$$ digits ) digits same as original and next $$$k-x$$$ digits greater than original. So already, the prefix of first $$$k$$$ digits is greater than given number. Then repeat it to make answer till $$$n$$$ digits.
you have 300iq s
In problem B div2 I just generated all possible x's and took the most frequent one. Is that right? 67350595
I really liked 1269D. To me, the solution seemed very non-intuitive though. (Like I couldn't understand how that train of thought could originate in the first place).
One question I had about it was, wouldn't this chessboard coloring logic be applicable even if the heights columns were not in a non-increasing order? I'd like to understand why this logic would fail in that case.
Any help would be appreciated.
1 0 0 1
or
1 2 1 1 2 1
it's possible to get non-connected diagram.
Ah I see! It was quite silly of me to miss that. Thanks for pointing it out. Btw, I still find the idea of coloring the diagram in white and black quite elegant. Would you happen to know if this is a well known idea (like are there other problems which use similar techniques) or did people come up with the solution on the fly during this round?
I don't know another problems like this, but coloring board with chess order is common idea. Another idea with 1x2, 2x1 tiles is bipartite matching of graph with vertices as board cells and edges between cells that have common side. Its equivalent problems. Interesting thing about domino tilings is Aztec diamond. But have nothing common with div1B problem )
Coloring chessboards and packing there some weird shapes is one of the most popular genres of mathematical olympic problems and packing dominoes into a 8x8 chessboard with two opposite corners removed is the most classical problem in it (which I learned in first half of my life)
I always look forward to contests with a single writer behind them and 300iq did not disappoint with this. The questions were really good !
How to solve the bonus question of $$$B$$$ ?
I have written code for div2C as per logic: 1) First, simply repeat 1st K characters and compare 2) If new_string is >= old string, print it 3) Otherwise, look for the index from first K character (starting from last one) for which if you iterate over K-sequence of (index, index+k..), then old_str > new_str. If so, increase the character value at that found_idx and at other position in its K-sequence order. After this, make all character K-sequences in between found_idx and K to '0'. I couldn't find the flaw in above logic and thus couldn't see why am I getting WA. Test case on which it's failing is pretty HUGE itself. I looked for other test cases from accepted solutions but still got the correct answer. Can someone please help me out of this trauma? My submission Link
Consider this input.
The answer is
5 12212
, while your code produces5 13013
.Thanks a ton for replying with a test case..:)
Sorry for trouble! I have solved it.
Clarifying the editorial's $$$Div1B$$$:
Suppose you mapped the diagram to a chessboard, where the white cells count is $$$w$$$ and $$$b$$$ is the black cells count. We can see that the upper bound of dominoes we can put is $$$min(w,\, b)$$$. But what is the proof that we can always achieve it?
Let $$$a_i$$$ be number of available cells in the $$$i^{th}$$$ column. Starting with the original diagram, try always to place a vertical domino in a column i where $$$a_i>a_{i+1}+1$$$ (decreasing $$$a_i$$$ by $$$2$$$), or a horizontal domino on top of 2 columns $$$i$$$ and $$$i+1$$$ where $$$a_i=a_{i+1}$$$ and $$$a_{i+1}>a_{i+2}$$$ (decreasing both $$$a_i$$$ and $$$a_{i+1}$$$ by $$$1$$$).
Both of the previous $$$2$$$ operations will not change the property of $$$a_i\geq a_{i+1}$$$, and will not change $$$w-b$$$. If you can't do any of the previous 2 operations any more, then you have reached a configuration with values of $$$a_i$$$ being $$$t$$$, $$$t-1$$$, ..., $$$2$$$, $$$1$$$. In this configuration $$$b\neq w$$$, this means that $$$b\neq w$$$ from the beginning (So if $$$b=w$$$ from the beginning, you could have filled the entire diagram).
If you didn't fill the entire diagram, how can you still achieve $$$min(w,\, b)$$$? Assuming without loss of generality that the column with $$$a_i=1$$$ (the $$$t^{th}$$$ column) has a white cell, we can see that $$$w-b=\lceil \dfrac{t}{2} \rceil$$$. So if we kept putting vertical dominoes, we will end up with leaving exactly $$$\lceil \dfrac{t}{2} \rceil$$$ cells (the number of columns with odd $$$a_i$$$).
300iq can you please elaborate on how to solve problem E of Div2
I was unable to understand the editorial
Can anybody please explain me how to get second value for each k in div2 E how to do it with segment tree
I guess you can initially have all values set to $$$0$$$. As you increase $$$k$$$, set $$$a[k]$$$ ( this array is the one on which segment tree is build ) to $$$1$$$. Then at every k, you have $$$1$$$s on some positions. I don't know how to do it, but now the problem is, given an array of $$$0$$$ and $$$1$$$, find minimum operations ( swaps ) to get all ones together. As editorial mentions, this value should be sum of indices of $$$1$$$s to the right of the median $$$1$$$ minus sum of indices to left of median $$$1$$$ ( think of it as right side $$$1$$$s have plus sign, and left side have minus sign ). Also, on each update, atmost $$$2$$$ signs will change, so you can handle sign change on update, and then keep track of the sum of the indices ( with sign ).
I knew that it's possible to use segment tree, but I was unable to came up with it during contest.
Then, after a while, I realized key observation: all times you add $$$k$$$ ! I know, it sounds ridiculous. But listen. You add $$$k$$$ <- this is last in sequence. In other words, it's biggest number. So, you don't have any number higher than $$$k$$$. According to inversions, the impact of including $$$k$$$ is number of all inversions with it. To calculate this impact, all you have to do is find all numbers less than $$$k$$$ at positions with higher indexes than $$$k$$$. But they all already less than $$$k$$$.
This means, that if you hold in segment tree all numbers from 1 to $$$k$$$, your request is just: find all X that has index higher index of $$$k$$$.
With segment tree, it's just sum of ones from (position of $$$k$$$)+1 to $$$n$$$.
Oh, sorry, I thought about inversions. it was harder to me.
About swaps with segment tree. Lets note $$$p_i$$$ initial position of 1 and $$$t_i$$$ position we want. Then total swaps:
Why? Because it's useless to swap 1 with 1, so we just 'pack' them. Now, split into two sums:
First and last sum is sum of arithmetic progressions. You can find them by formula. Other two are just sum using segment tree or fenwick tree.
Ohh can you explain it more please. What is $$$t_i$$$ and what does mean 'pack'? Please )
$$$t_i$$$ is target position. Look at following example:
Then $$$p = [2,6,10,12,15], t = [8,9,10,11,12]$$$. So, sum is
I pick word 'pack' because you can imagine this by 0 — space, and 1 for example pens, and you just move leftmost towards center and rightmost towards center and they meet together.
Hey, in case of even number of 1s you "pack" them towards which of the two medians?
I pack towards best of two, calculate cost of both. It should work if indepentence is correct (I don't know proof).
ok
you can prove that both medians has same sum, using same argument that minimum should be median.
you are the best) thank you) I got accept
This helped me to understand it very well THANK U
What was the logic you all used in div2a i am having hard time understanding tutorail.its normal to not able to solve que i can solve a b sometimes but sometimes i have problems,
If a — b = n, then we can rewrite a as (x+1) * n and b as x * n. In order for both (x+1) * n and x * n to be composite, we need n to be at least equal to 2.
Basically, you can print every possible pair of type (x+1) * n and x * n as long as x >= 2 and (x+1) * n <= $$$10^{9}$$$
There is tricky test n = 1. For that case 2,3,4,5,6,7 doesn't work.
good point
Can anyone tell me what is wrong with dp approch in div 2 D https://codeforces.net/contest/1269/submission/67394114 I have first converted a[i] to a[i]%2 that is making the sequence 100110... 1 if odd 0 if even. Then I note compute dp[i] as the min no of squares up to column i that can go unfilled.For this I use the following observations, 1. we can use the full column of even length (dp[i]=dp[i-1] ) 2.if columns are of the form 111..m times (i.e all odd), if m is even then all the squares can be filled, if m is odd 1 square is not filled. 3.sequence of the form ( 1.. even times 0..1 ) can be completely filled.(you can take example of 3 2 2 3) Am I missing something??
Will an editorial for all problems on the actual ByteDance contest be posted?
In Div2 D, why do we have a contradiction?
Does the proof still work in this case?
2
1 1
I think it has an equal number of white and black cell.
I think that it doesn't meet the request in the editorial "If all rows and columns are different".
Can anyone please tell why O(n2) solution doesn't work in Div2 B? Please have a look at my submission and help.
O(n^2) submission works and your submission for the problem is accepted. What's wrong?
It's not accepted. I'm talking about modulo problem!
Oops sorry, I looked at the wrong row
Weak systests in Div2B. Some test cases where multiple
x
values existed, submissions have passed without taking the minimum of them. Example test case:Here both x=1 and x=3 are valid and output should be x=1. But hacked submission outputs 3.
What does hacked submission mean sire?
Users with 1900+ rating can hack a submission even after the contest is over. It does not result in decrease of points of submitted code though.
it got rte in question B. I used vector rotation. Where is issue?
Can someone explain Div2 D, the domino problem?
In div2D/div1A, I understood the soln but what is the significance of "column lengths will be in sorted order"?Even if it's not sorted this algo shud work right?
For Div2 E. I can not get how to maintain the second answer. Who can explain more, thanks.
Let $$$a_i$$$ be the number of $$$1$$$ after place $$$i$$$, $$$b_i$$$ be the number of $$$1$$$ before place $$$i$$$.
You're going to work out $$$\Sigma_{i=1}^{n}min(a_i,b_i)*[place_i=0]$$$ while each time a $$$0$$$ changes to an $$$1$$$.
It's easy to conclude that $$$a_i$$$ is non-increasing and $$$b_i$$$ is non-decreasing.
As a result, there exists an $$$i$$$, which satisfies that for all the $$$j \leq i$$$, $$$min(a_j,b_j)=b_j$$$ and for all the $$$j>i$$$, $$$min(a_j,b_j)=a_j$$$.
So just do a binary search to find $$$i$$$ (Or, according to the definition of $$$a_i$$$ and $$$b_i$$$ it is the median of all the $$$i$$$ that $$$place_i=1$$$), and the answer is $$$\Sigma_{j=1}^{i}b_i*[place_i=0]$$$+$$$\Sigma_{j=i+1}^{n}a_i*[place_i=0]$$$.
You can work it out on a segment tree.
This is my code and I hope it can help you more: 67425987
Thanks very much!
Can you explain how we do calculation after finding median i?
I mean.. Okay, we got that we have to add to the answer sum of Ones before 0 (if 0 is before i) and sum of ones after 0 (if 0 is after i) for all zeros
After finding median $$$i$$$ you realize that for all the $$$place_j=0$$$, if $$$j \leq i$$$, then the contribution of $$$j$$$ is $$$b_i$$$, else it's $$$a_i$$$.
Consider that each time a $$$0$$$ changes to $$$1$$$.
You can maintain it through the following steps: (suppose that $$$place_k$$$ changes to $$$1$$$)
1) Let $$$a_j$$$ $$$(j \in [1, k-1]) = a_j + 1$$$, $$$b_j$$$ $$$(j \in [k+1, n]) = b_j + 1$$$.
This can be realized on a segment tree.
2) Erase the label $$$k$$$ in $$${a_n}$$$ and $$${b_n}$$$.
To achieve this, you can maintain a $$$size$$$ on the segment tree node to show how many labels are still existing on the range that this node stands for.
Then when you are going to add $$$1$$$ on a whole segment tree node, you can simply add the $$$size$$$ of the node to the $$$sum$$$ of that node and leave a lazy tag there.
If you still have problems you may view my code above to better understand it.
I see a tag of "Graph Matchings" on DIV-2 D, how the problem can be solved using such an algorithm. I couldn't see any mention of it in the editorial though.
All cells are node. Edges between adjacent cells. You get a bipartite graph. Find the largest matching in it.
Can someone please explain for Div2E how to calculate the second value(mentioned in editorial)? And why does it work(taking the median)? I understood the inversions part but unable to get the median thing!!
How DIV2 B can be solved in O(N)?
How we can solve problem D using graph matching as given in tag ??
All cells are node. Edges between adjacent cells. You get a bipartite graph. Find the largest matching in it.
But there are too many cells so the time limit will exceed
Using hall's theorem you can show that the maximum matching set will have the same size as the smaller of the two bipartite sets. So you don't actually need to solve the flow problem.
Can you explain a little more?
I mean that consider the graph you get as $$$G=(X+Y, E)$$$. Creating this graph and then getting $$$X$$$ and $$$Y$$$ is easy in $$$O(N+M)$$$ and since $$$O(M) = O(N)$$$ the result is $$$O(N)$$$. Now using Hall's Theorem you can say that the maximum bipartite matching will have a size of $$$min(|X|,|Y|)$$$. You don't need the actual coverings.
As for why Hall's theorem is applicable, assume $$$X$$$ to be the smaller set with LOG. We can use induction on the size $$$A$$$ where $$$S$$$ is a subset of $$$X$$$. The base case is trivial, there must be one edge from the $$$S$$$. Now, notice that whenever we add a another node to this subset, it must add at least one new node to the neighborhood. Therefore, the proof is complete.
Why must it add at-least one node? Well, I haven't been able to prove that part yet but I'm pretty sure it's related to being the smaller set.
Thanks I understand
Div 1.C — Div 2. E
The editorial says (or at least i understood this) that it's optimal to put the first $$$k$$$ elements together (consecutive) with the minimum number of swaps and the sort them (and because they are together we have to add the number of inversions), but why is this optimal?
The approach for Div2 D is very interesting. Just wondering can we use it for the case when size of domino is 1X3 or 3X1 (coloring the board in 3 colors and finding the minimum number of occurence of those colors)?
so weak pretests 300iq can you explain me what the fuck is this do you really think it's normal?
P.S. Я не лайко попрошайка, но блин, уже -12, я не ожидала о_О
I think I have a clear proof on 1269D, so I would like to post my proof here.
Without affecting the answer, we add
'0'
at the end of the histogram.We define two operations:
Example:
8 7 3 1 -> 8 7 1 1 -> 8 1 1 1 -> 2 1 1 1
Example:
3 2 2 1 -> 3 1 1 1 -> 3 1 0 0
Repeatedly do the operation (1) and (2) until you can't. Note if no neighbour difference $$$ \geq 2 $$$ or $$$ = 0 $$$, then all neighbour difference $$$ = 1 $$$, which is "basic diagram" stated at the editorial. We then can just choose all dominos vertically on the "basic diagram".
How to prove that if (a + x) mod m = b then x = (b — a) mod m
$$$a + x = b + km$$$ for some integer $$$k$$$
Subtract $$$a$$$ from both side
$$$x = (b - a) + km$$$ for some integer $$$k$$$
$$$x = p + qm, (b - a) = r + sm$$$ for some integer $$$p, q, r, s$$$ such that $$$0 \le p, r \le m - 1$$$.
$$$p + qm = r + (s + k) m$$$
Subtract $$$qm + r$$$ from both side
$$$p - r = (s + k - q) m$$$
$$$s + k - q$$$ is integer, and by line 4 $$$-m+1 \le p - r \le m-1$$$. So only solution is $$$p - r = 0$$$.
Add $$$r$$$ for both side
$$$p = r$$$
$$$x \mod m = (b - a) \mod m$$$
thx
ko_osaga hello I have a doubt why didn't you take mod m both sides in 2nd step only
x = (b-a)+km;
take mod m both sides
x%m = (b-a)%m
This gives us the same result is there is something wrong in my way?
Another way of thinking 1268E. Consider the problem is: given the start edge, how many possible increasing paths from that start edge? If we can answer this question, then the solution of starting from a vertex
u
is the sum of solutions of edges that are adjacent tou
.For a given path
e
, it is easy to find all the feasible next paths ofe
. Namely, if the weight ofe_2
is larger thane_1
, thene_1 -> e_2
is feasible. The relations, such thate_1 -> e_2
, form a new graph, which is DAG. Thus, it is trivial to find a solution to the new problem.Note that the edges should be directional. You should convert the original undirected edge to two directed edges.
Can someone explain to me the idea behind Domino for Young?(Problem D Div 2). Can someone tell me why this greedy approach fails as well? https://codeforces.net/contest/1269/submission/68692876
This is a small test case with which you can see why your solution is incorrect. If I did not misunderstood your program, it will output 7, yet the answer is 8.
Thanks for the test case. Can you explain to me what the editorial exactly says? It is a bit difficult to understand
Editorial for that problem has two parts:
Which part do you have trouble with?
I'm fine with the general coloring argument. What I do not understand very clearly is the first part. The second part was pretty intuitive.
That part has further two part:
Part 1. is pretty easy, so the editorial does not elaborate it: However you place a domino it will occupy one black and one white cell, so if you've tiled all cells with dominos, it is necessary that you have as many white cells as blacks cells which both equal the number of dominos used for the complete tiling.
Part 2. is harder: we first notice that if we delete two equal columns from the diagram and we can tile the resulting new diagram, then that means we can tile the original too. Let's call the new diagram D2, the original D1.
We can tile D1 the same way as D2 (as they're largely the same) with these two differences:
We can say the same thing about rows of equal length, that is: It is also true that if we delete two equal rows from the diagram and we can tile the resulting new diagram, then that means we can tile the original too. (This can be shown the same way as with columns)
So, now we start to reduce our diagram which has equal number of black and white cells. After we delete equal rows, then equal columns, then again all equal rows, then again equal columns and so on, what do we get? For the resulting diagram we can't get anything but a "basic" diagram, as anything else has either two equal rows or two equal columns. However, we also can't get a "basic" diagram, as every basic diagram have different number of black and white cells, while our row/column deleting operationg preserves the difference of the number of black and white cells. So we can only end with "nothing" which can be completely tiled with dominos (with 0 domino), so consequently the original diagram can also be tiled completeley.
I solved three last problems (div1-CDE) during a live stream, https://youtu.be/RrzIwj5k6cY
I don't like graph problems but those weren't that bad and ugly :D
Problem D: Domino For Young: the solution works even if we don't have non-decreasing heights. So why put that as an additional useless condition?
300iq
It will not work if heights are not in non-descending order.
Can anyone tell what is wrong with my solution?
86348075