Good day to you, Codeforces!
Let me introduce you Codeforces Round #539, that will take place at Saturday, February 16, 2019 at 19:35. The round will be rated for both divisions.
The problems of this round were developed by markysha, xolm, aleex. That is our first round on Codeforces, and I hope not the last one :)
Thanks everyone who helped with tasks preparation:
- Our coordinator arsijo for his help with everything
- Thanks very much 244mhq, Mediocrity, sharepoLOVEDDD, austrian_artist, Adalbert, stanislav.bezkorovainyi, Fekete and Daryusz for testing this round (yeah, we approached testing thoroughly :))
- gepardo for playing a crutial role in the contest (what? you'll see)
- And of course MikeMirzayanov for Polygon and Codeforces.
There will be 6 tasks and 2 hours 30 minutes to solve them. As usual, the score distribution will be revealed shortly before the contest.
Wish you quick ideas and short solutions!
Upd.
Div. 1: 500 — 1250 — 1750 — 1750 — 2250 — 3000
Div. 2: 500 — 1000 — 1500 — 2250 — 2750 — 2750
Editorial
Final results are ready!
Div 1:
1. Um_nik
2. jqdai0815 (was so close...)
3. knightL
4. Swistakk
5. ToTLeS
Div 2:
1. schtamas
2. CheimaKH
3. revivedDevil
4. zhed
5. 1100011101
Congratulations to the winners!
Maybe see you later...
6 days wait is over. :)
hoping for a hell of a contest
yeah it will be one atrocity of a contest. this guy has never made a contest before so we can expect the worst...they are just making fun of us at this point
How many shared problems between Div. 1 and Div. 2?
I think 4, but it is not certain.
So you think div1A will be div2E? No way.
Oh, I mistook. The meaning of the previous comment is "Div1.A = Div2.C", but I momentarily mistook the meaning of shared problem as that of not shared problem.
4 shared problems doesn't mean div1A = div2E. 6 problems for each division, with 4 shared problems i.e,
I posted that before he edited his comment.
Oops! Missed that.
Yes. At first I mistook, and (through his comment) after knowing that I edited the commen. But I had to accept the downvote due to the mistake. Maybe it was and is a good experience...
That's why people despise the 'codeforces community' , as they given 100's of down-vote(s) to guys who might have done a very small mistake even without knowing . You guys should not spread your frustration and negativity to others :-) (to the down-voters)
"(yeah, we approached testing thoroughly :))" This is important. I hope this is true.
I also hope)
congratulations on your first contest.
Is there a separate contest for both divisions or combined for both divisions?
Separate
There is actually a link in the post.
do you even care about us anymore? the last few contests were like bad jokes full of math and other useless stuff. what happened? why did we stop getting good contests? are we not worthy anymore? do we not matter for you anymore? you just wanted us to make the statistics and now you shit on us?
But why do you incur receiving negative vote by yourself? Your tone is the reason why there are a lot of negative vote on your comment. The same will be true of other comments. As I checked, 47 of your 60 comments received negative vote, 11 received zero sum of positive and negative vote, and only two received positive vote. And few people will think well of your comments though you may be going to post more comments in that tone.
the truth hurts and that’s why people are downvoting. they know what i’m saying is true and are mad so they are downvoting me to make them feel better
make good contest or die
Hope this will be a fun and well-made round.
Good luck to all participants!
do you even care about us anymore? the last few contests were like bad jokes full of math and other useless stuff. what happened? why did we stop getting good contests? are we not worthy anymore? do we not matter for you anymore? you just wanted us to make the statistics and now you shit on us?
Finally I can have my chance to participate (I attempted to evade 2 previous rated contests to preserve the color formation) :D
Guess now would be my perfect chance to do good (or maybe do bad and reach purple, who knows :P)
Good luck!
I am really sorry, that your preserved color is gonna fade away :|
Somehow I predicted this to be happening... :<
Congratulations on your first contest! Will this round feature any interactive problem?
NO GreenGrape xD.
If the site does not collapse i think it will be a good round. I wish good luck to everyone!
Make good contest and hope no 404Error or sitedown issues.
Oh,404Error......
Please ensure that the pretests are strong. There has been a spate of weak pretests in recent contests.
Hacks are part of codeforces contests
it will be rigged as always
be more optimistic :)
about what? all odds are against us. newbie contest maker (it’s his first ever) so we can expect the worst and they are treating us miserably. there really isn’t anything to be optimistic about.
All the authors have a great life experience in making contests, so please think twice before saying something.
please think twice before posting a contest
please think twice before posting a contest.
There has been a spate of weak pretests in recent contests.
Hmm, no, have you been too obsessed with CodeCrafts?
AFAIK two most recent contests are fine.
jinlifu's round is a pretty good round ruined only by server issues.
And about my contest, please research closer (all following data is calculated during contest time):
B might be a little weak of compared to the other (yet oddly not even a hack was made), and E's random nature makes hacking it inevitable. Still, the fail ratio is still not even one-sixth yet.
I was talking mainly about round 537(codecraft). I apologize if it sounded accusatory or was worded badly.
"recent contests" sounds like you're summing things up.
Be specific, and optimistic. ;)
i am with a hope to cross rating 1200
wow~ any interact problem?
No, we would say if there was an interactive problem
Any clue when this will stop? I hope we eventually get to a point where interactive problems are just treated like normal problems.
Good luck to everyone.
really no one cares
Congratulations on your first contest..love to see div2 contest
I wish everyone high rates!
Is it rated?xD.. hopefully so because my first contest.. wish you all good luck
Why the downvote on me comment? I say good luck to all.. !!
It is better to refrain from containing "Is it rated?" in the comment.
A bad time for Chinese players :(
It's always a bad time for someone, quit whining.
Best of luck every one.
It's my first div1 contest...A bit nervous...
Anyway,good luck to you all.
I had that feeling too in my first Div. 1 round, luckly things ended up great and I solved 2 problems earning +76 :D
Good luck
I'm in the same boat (@1904). I'm both nervous and excited! Good Luck!
is it rateed?
The round will be rated for both divisions.
Are you gay?
People are free to choose their sexuality.
The problem:A in Div.1 will be which problem in Div.2 ?C or D
Hope short and clear statements...
Best Of luck everyone
Best of luck to you also
So far there are no registrants with rating 2019...???
yay — a contest that california people can take! good luck everyone!
bad timing for chinese... im sleeping during that time...
How can sleeping time be bad ?
Finally! Indians can have their dinner and give the test
Good luck!
Finally contest comes after 6 days
Good Luck
I can't submit. When I click submit the "You have submitted exactly the same code before" notification appears, also I can't ask questions :/
Wtf is wrong with pretest 7 on Div2.B?????
try: 2 100 1. should give you 20.
Atmost 1 operation can be performed by the farmer. Trying to perform more than one operation results in failure in this test.
a xor b xor c means ((a xor b) xor c) ?
There's no matter in how you place the brackets
Does someone have to post this every time?
You stole my up-votes xD
What the hell "@yourfavoriteexgf" is doing in that image??
In Problem C Div2 what are l and r?
The boundaries of the range described
Very nice contest, was eagerly waiting for it...
Was there at all a successful hack today?
I saw a person with +3:-2.
Oh okay thanks.
But all I could find was -1 or -2 hack counts.
You can always go to the contest->status and use status filter to see all successful hacks in the contest.
Wow, thanks alot. This is something I never knew that it existed even after 2 yrs of cf.
whats wrong with protest 7 (problem B)
Your solution might have a bug.
how to solve c? my code TLE testcase #9 T^T
tle in 11 worst case takes around 3 seconds tried every optimization :(
Though I didn't participated but I think dividing prefix xors for even and odd indexes should work
my idea is xor(l~r) = xor(xor(mid~r),xor(l~mid)), but i didnt optimize to find this for every array..
This might help:
Let's say you have numbers A and B. C = A XOR B Then C XOR B will be A. You can use this in ranges too
Let's consider segment (l, r] where r-l is odd, then
p[r] xor p[(l+r)/2] = p[(l + r)/2] xor p[l]
p[r] = p[l]
Now it's simple thing to calc.
How to solve div2 Problem C?
Maintain prefix XOR. Partition the indices with two of them in the same set if their prefix XORs are same. Maintain separate count for odd and even indices in each of the partitions. Answer will be the sum over all partitions of (odd choose 2) + (even choose 2).
First, note that the problem can be reduced to
count number of subarrays given xor
by noticing thata[i] ^ a[i+1] == a[i+2] ^ a[i+3] equals to a[i]^a[i+1]^a[i+2]^a[i+3] with zero as a result.
Hence, given xor will be 0.
Since the problem limits to even-size array only, we need to modify the array a bit. We can try to merge every index i and i+1 (i.e. a[1]..a[n] becomes {a[1]^a[2], a[3]^a[4], ... } Then the problem simply becomes count number of subarrays given xor.
But, another caveat is that we only handle even indices. We also need to create an array consisting of {a[2]^a[3], a[4]^a[5], ... } to handle odd indices.
P.S. You can simply google how to count number of subarray given xor
I think there is a problem with finding number of sub arrays with xor 0.
a[i] ^ a[i+1] == a[i+2] ^ a[i+3] equals to a[i]^a[i+1]^a[i+2]^a[i+3] with zero as a result
The converse isn't true for this statement, i.e., if xor from range [l, r] is 0, that doesn't mean we can partition it such that xor from range [l, mid] = xor from range [mid + 1, r]Can you give an example?
Yes you are right. I made a mistake. If the xors of left range and right range were a and b, where a not equal to b, then a xor b can never be zero.
Ignore my original comment, I was stupid :<
Are you sure? Can you provide contrary instance for second?
It is always true. Do you have an example when it's not?
Oops, I was going full mad. Sorry guys :<
How to solve div2 D ? sashan and one more name ? Any idea .
btw good contest , div2 a was also a little bit thinking .
how to solve Div 2 C
How to solve Div2 D?
Hint : Answer belongs to {1, 2, Impossible}
Assuming my solution works:
You can split the problem into two cases, a palindrome of odd length and even length. For both cases, you can notice that the answer will either be 1 or two. That's a major hint.
For odd cases: Checking for the "Impossible" case isn't too difficult so I won't explain that. The answer will always be 2 for this case otherwise (we can cut a prefix and a suffix of the string a "swap").
For even cases: If both halves aren't palindromes, the answer is 1. Else, we can check if we can cut some prefix and append it to the back to form a palindrome that is different from the original one (if yes, the answer is 1). Otherwise, the answer is 2 by the same reasoning as the odd case.
Div2D: Solutions fall into 3 cases: {1,2,impossible}.
Let's think of a palindrome as consisting of "mirrored" part and a possible "center" character. For example, "abcxcba" has "x" center and "abc" mirrored part.
Impossible case: input where the mirrored part consists of only 1 character. For example, "qq" or "qqqxqqq". If the mirrored part consists of more than 1 character, for example, "abcxcba", then we can always solve with 2 cuts (cut the outermost 2 characters from both sides in the example).
So if the answer is not impossible we just need to check if a 1-cut solution is possible. If it's not, the answer is 2. Since input length is only 5000, we can try all possible places for 1 cut, check that we get a palindrome, and that the palindrome is different than the original palindrome.
What is so specific to test 9 in div1C? It's killed me...Also I really don't get why C. The other problems seemed decent, but this one is just coding. D was nice, E was very DSish (I'd personally rather find its place in an educational round). Didn't have time to read F. I absolutely loved B.
Can you explain D?
It's pretty mathy: you have to know prufer codes. Basically you can infer the following thing: the number of trees on N nodes with given degrees d1, d2, .., dN is the multinomial coefficient on the array d(i)-1, that is: (N-2)!/product of (d(i)-1)!. That comes from the number of arrays of length N — 2 where i appears exactly d(i)-1 times. It's easy to prove that once you know the bijection between the prufer codes and the labelled trees. Now, assume you've fixed the distance between the 2 nodes to be K (note the actual 2 nodes don't matter and you can ignore them, I for one, haven't read them). That implies you should have K — 1 ordered nodes on the path between them. There are (N-2)(N-3)...(N-(K-1)+1) ways of doing so. Then, let's assign their weights: the number of ways of writing M as sum of K numbers: C(M-1, K-1). Then the rest of the weights are free to take any value: M^(N-2-K). Now we're interested in the actual number of trees. Let's contract the K+1 nodes on the path into one big node. The thing is that you now care about the degree of that big node. Assuming it is d, you have to multiply the answer by (K+1)^d because for every node that has chosen it to be a neighbor, you need to assign an actual concrete node out of the K+1 small nodes that make up the big node. So if you iterate d, then you can choose the d-1 spots where the id of the big node will be placed and complete the rest of them with anything. This is N^2. The inner loop (the one that iterates d) can be algebraically manipulated to look like a constant times a sum of C3*C(C1, i)*C2^i which gives C3*(C2+1)^C1 where C1 and C2 are some constants that you can find by grouping together things that are dependent on d and things that are not. You then get NlogVmax because of some raisings to power (that I think you can skip if you really want to, but there's no need for that).
Thanx a lot!!
Can you please suggest any tutorial for prufer codes and some related problems?
You should not take into consideration events that appeared before l. In other words, the initial s on the interval should be 0, not the last speed that was set before l. Such a fix changed my score from "Wrong Answer on test 9" to "Pretests Passed".
Fuck...Thanks for telling me. Now I can die peacefully
Very good and balanced contest! Thanks to writers.
How to solve div1 D?
https://en.wikipedia.org/wiki/Cayley%27s_formula #generalizations
Then you just enumerate the number of points between A and B
Knowing how to google properly gives 1750 in div1! How motivational
do we need to know the above theorem to solve it . if yes , it must be pretty hard for them who have no idea abt. cayles theroem
you can derive it by https://en.wikipedia.org/wiki/Pr%C3%BCfer_sequence , which seems intuitive enough, i guess
There is a very interesting question still remains: how to find a number of different paths with length i and sum m?
UPD: sorry for the stupid question, it was just Cnk :)
You can use stars and bars method
Found the formula, thought it was useless, skipped XD
Also, there is no such a generalization in the russian version of the wiki page.
I'll take a note about always reading English version.
Sadly, I didn't give too much attention to the generalization section due to the round pressure.
So, in the end, I spent some upsolving hours creating my own generalization based on the specific Cayley's formula proof by double counting (https://en.wikipedia.org/wiki/Double_counting_(proof_technique))
But, afterwards, it was rewarding for me to see that it was a relevant result.
Use cayley's and basic combinatorics to find the number of trees in which we have k edges in simple path from a to b. (a, b doesn't actually matter)
let's renumerate vertices a = n — 1, b = n. Than think about Prufer Code. You'll have path between n — 1 to n with number of edges >= e if Prufer code ends with (e — 1) sequence of distinct numbers that are less than n — 1. Than you can find formulas for dp[e] (it's just what is written above) to make number of edges == e just subtract from dp[e] , dp[e + 1] and dp[e + 2] ... Implementation for details 50017868
Sad thing is I looked at that page but skipped past the formula. Sad face!
Nice problemset, especially 1B and 1D ;) (though I failed both miserably :D)
how u solved div1 b ?
A little bit intuitive (I didn't make it to prove just yet), but the answer can only be either 1, 2 or Impossible. Thus, this can be solved by some bruteforce.
Well, I think you can prove it by showing that if you swap a prefix of s with a suffix of s such that the prefix/suffix is not a palindrome, then it will be sufficient. Because of this, as long as the n/2 prefix and n/2 suffix are not all the same letter, it is possible in 2 moves or less. Then you can brute force to check 1 move solutions.
Problems were very interesting to solve. Thanks for your first contest! :)
It took me nearly an hour to realize that if a_l ^ a_l+1 ^ ... ^ a_r = 0 then a_l ^ a_l+1 ^ ... ^ a_x alway equals a_x+1 ^ a_x+2 ^ ... ^ a_r
thinking in C dp gave me headache but it was a nice problem
Can someone pls tell what is wrong with this code? https://mirror.codeforces.com/contest/1113/submission/50033374
i dont know if this is helpful, but testing your code against: 2 1 100. gives me 100 instead of 20.probably you're missing the fact that your meant to perform the increase & decrease at most once.
It's giving 20. Can u pls check again?
sorry my mistake. try 2 100 1. should give 20. but gives 101.
second for is from 1
Ok got it.My bad.
Is Div2E/Div1C solved by doing minimum-prefix-sum query with segment tree?
Nice problems! The round was quite hard but it isn't a bad thing, I guess.
for div1d , have u used cayles theorm ?
I described my solution under the editorial: https://mirror.codeforces.com/blog/entry/65295?#comment-492971.
Can anyone please tell me what's wrong with this code: https://mirror.codeforces.com/contest/1113/submission/50029202
for to 1 instead of 0
its sorted so you don't have to consider first element...because i am multiplying factor with arr[0] every time.
should be 5e4 + 1 :/
silly mistake:( thanks for pointing it out...
yea, it's the worst :C
In 1B, I completely missed that the initial string was a palindrome, I was trying to solve for general string(as constraints were bit low), after struggling for 30 mins I re-read the problem.
-
What will you do when all numbers are odd?
What about this one?
5
1 3 5 7 64
Optimal X = 8, operated on 64
Can anyone tell me why this DIV2B code is WA? `
`#include <bits/stdc++.h> using namespace std;
int ada[101]; int a[500005];
int main(){ memset(ada,0,sizeof(ada)); memset(a,0,sizeof(a));
}
answer is 22, your program is giving 23
Next time you want to put some code in comments, I suggest you using pastebin, ideone, link to your submission or even the thing called "spoiler", because it's not very nice to put your long code in the comments section)
Use a spoiler tag. A long code comment makes it difficult to read all the blog comments. Especially on mobile.
Blackness & dragn78 .. 1 user, 1 room, 2 accounts.
room : https://mirror.codeforces.com/contest/1113/room/216
Why the system testing hasn't started yet?
Probably there is some dispute about tasks.
Oh I almost got Div.1 D, I was just having some bugs and didn't get it on time.
Amazing problem-set, enjoyed every minute in the round
Damnnn!!! Completely missed that initial string is palindrome in Div2-D. fml.
Me too :(
For more contests on the weekends : )
MikeMirzayanov I think this should be considered as cheating. look here
The person who has done this 6-vkcom-stupidjokesproga
This is hilarious. What are the odds that his alt account and him were assigned to the same room.
I think that he has many alts, so it is more likely to get in the same room as one of his alts.
Birthday paradox at work.
Only if he's willing to get rating on any of the accounts. It's much more likely that he has one main account and multiple helpers and then birthday paradox doesn't apply.
The contest with least Hacks and System Test Fails !
div2-C I think the question is ambiguous.
That's why they are giving that specific sample.
good contest. :)
road to yellow
Fairly
Follow my lead
Well, that's actually an aim for some people :)
It seems that systests for problem Div1C don't contain test with query similar to
3 1 1 0
I resubmitted my solution, because found that my first version printed '-1' on this test, but it should print '1'. After contest I submitted first version and it got AC too.
For what question?
I think he is talking about div1C
Oops I was wrong..
Yeah, it was about div1C, i missed it >_<
Can anybody tell me why my 1st solution for div2D is giving wa on 8 but when I changed the code a little bit with even less memory it is giving MLE on test case 1. MLE solution
WA on 8 solution
It seems you did more than one change. Inside main there are two nested loops and an unused variable g in the WA8 code. Then you used it in the MLE solution. I've taken your MLE code without using said g variable and it uses less memory but still WA8. I guess you did some logic corrections wich ended in MLE, maybe you didn't set properly the values in P matrix, what do you think?