It's almost here! KickStart rounds kick off this Sunday, March 24 with Round A at 4:00UTC. Get ready and register now at g.co/kickstart.
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | 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 | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
It's almost here! KickStart rounds kick off this Sunday, March 24 with Round A at 4:00UTC. Get ready and register now at g.co/kickstart.
Name |
---|
The URL is appended after codeforces/blog/entry, please fix that : )
Ups, sorry, already fixed!
What would be the difficulty of the round ?
It's hard to estimate... You can check previous rounds to have some grasp on the difficulty. I'd say it's easier than the Code Jam, but this is my personal opinion.
yes , , but you said easier than code jam .
which round you are considering , QR , R1 , R2 or ,WF ?
I can't see/view the problems/scoreboard :(
EDIT: Now it works
its still not working.scoreboard is loading....
I see 2 people on the scoreboard, but where are the problems??
It's just loading OMEGALUL
https://www.youtube.com/watch?v=oTRy42ib4v0
codejam 2018: Guys we don't think it's a good idea to use the new UI kick-start 2019: GUESS WHAT
It's okay, even Googlers are humans. But they should still ensure such things don't repeat in the future rounds.
But yeah, we got something after Codechef to criticize xD
Yeah, I tried to hold my rants.... My temper have limits and I figured out that I should let some of it out after waiting for almost a year since last year's codejam.
Codeforces finally works... Didn't even have a place to complain about the competition...
Failed to submit C small... should've get a better rank. We even cannot say, "Hey, please make this unrated." like what we usually do when such things happen in Codeforces.
I was about to post the same comment here about 15min before the round was to end.
But even CF was down. Lol you won the race :P
Oh boy, I can't wait to see all the rants when codejam also transits into this UI and judging system. Good luck on dealing with all the lagging issues.
What was your approach on problem C?
Observation:
If A >= B (A fully contains B), there must exists some OPT ordering where B is ordered before A. (If A is committed before B then B will get 0 seats so obvoiusly no)
If two order does not share a seat then their relative order does not matter.
Construct a DAG from the >= relationship. We shall try to place "smaller" orders before larger ones, in a toposort fashion. Pick any order that does not contain a unprocessed order(segment), Pick all other orders which do not have an unprocessed >= relationship in the toposort and overlaps with the current order (recursively), call this a group. We binary search for k on each group (and take min of all afterwards), use two pointer to check if all order got at least "mid" seats (two pointer from i-th order in the group to j-th order in the group, the starting point of the i-th order is only affected by the ending point of the (i-1)-th order), while using some range query data structure to query the amount of unprocessed seats in the range.
Time complexity: O(n lg^2 n)
I am sorry but I cannot understand this. Did you try submitting it?
If so, can you share the code?
I submitted it after the editorial is released but it doesn't work, also fails in Errichto's test case :/
First binary search the answer. Let the current answer be $$$k$$$.
Consider the intervals in the reverse order (i.e. from the last interval in the schedule.). For example there are three intervals $$$[1,5], [2,4], [3,6]$$$, and $$$k = 2$$$ now. We know that $$$[1,5]$$$ cannot be the last interval since we know that if so, $$$[2,4]$$$ and $$$[3,6]$$$ already covers some range and $$$[1,5]$$$ can only have seat $$$1$$$. $$$[2,4]$$$ cannot be the last interval for the same reason, but $$$[3,6]$$$ can be the last interval. As long as there are intervals that can be put in the last position, we put them and the problem becomes a smaller one. If there are none, then the current $$$k$$$ is not possible, and we switch to smaller value.
Different implementations of this can lead to different complexity. It will be easy to get the small with the idea above, but I am still thinking about how to use data structure to solve large.
Just to add. I had similar idea for solving small. Instead of binary search always take the max length segment as the last segment.
Nice observation! Sounds like a way to help us solve large.
I think we can also say that there will atmost sqrt(n) distinct values possible for the max segment at each stage throughout but I still do not know how to use this and solve the problem fast.
Will it not fail for test cases like:
1
20 3
1 10
11 20
4 17
From problem C editorial:
"Another observation is that at every step we can always choose this request greedily from the remaining set: the one where we can book the maximum number of seats."
Shouldn't we pick the request which yields the min number of seats as it will only drops when we allocate more and more seats?
I thought so and found a countertest:
Great test case, max(min) always get me screwed...
Then picking max backwards do makes sense, picking max(min) in each iteration whlie allowing other requests to grow does construct an impeccable greedy solution.
how to solve B ?
In question B, if we take all zeroes except 1 at one corner, one of the accepted solutions will have a complexity of 10^9 and another code 4*10^8 for this test case. How does 100 test cases with similar test data doesn't give his/her code a TLE?
Hints for B and C?
Editorials were published and are available in the problem view.
In C, does the editorial simulate the process from the end?
"Another observation is that at every step we can always choose this request greedily from the remaining set: the one where we can book the maximum number of seats. ... At every step we intend to find the request where we can book the maximum seats, remove this request from the set and recalculate the number of seats we can book for the remaining requests. "
During the contest, I implemented a solution where we greedily take an interval with the smallest number of available seats. Got WA and then found a countertest :(
I am thinking about to choose smallest segment and delete that from set and go ahead, is there any counter test case for this?
Yes, I pasted it a few comments above. Intervals $$$[2, 8], [1, 4], [5, 8]$$$.
correct output and what is the order?
[5, 8], [2, 8], [1, 4], k = 1.
Come on, you could check brute force it yourself in seconds. You must take the last interval first. The answer is $$$1$$$.
got it,thanks
Why in this case the answer is 1? in first segment 4,5 in second segment 7,8 in third segment 1,2 Could you explain what I'm missing?
I think you misunderstood the statement. A query takes all the available seats in the interval.
Yes we simulate from the end, the previous line states
"We can observe that for a chosen ordering of the requests, the number of seats that we can book in the last request does not depend on the ordering of the previous Q — 1 requests."
Any proof for the observation stated above?
the submit button is not worked in last hour, I cant make submission for B and C then, what will be the solution of that? there is also a public announcement regarding this
I'd imagine they will end up inviting more contestants than usual and tell everyone better luck next time.
sad for me in very beginning of the day
Can someone please tell why I am getting Run-Time error for training Problem, My code : "https://ideone.com/e.js/oRGkWq
Even I want to know. What is the procedure of submitting there. Not close to codeforces way of submitting.Found this: https://code.google.com/codejam/resources/quickstart-guide but still unclear
Hi Abhinav, If you are using Java, You need to have your class name Solution. I wasted am an hour because of this. I should have read that guide earlier.
Why does my B WA?
I've done what the editorial said, it passes samples but fails the main tests
https://ideone.com/iDlNtN
I think there might be something wrong with my check function if I misunderstood the editorial
In my check function, I take maximum and minimum over all x+y and x-y for all points where their current distance from a post office is >k
Then I individually check each of these 4 values to see whether it can lie within the square with centre (i,j)
to do this, each of the precomputed values — (i+-j) must be less than or equal to k
Shouldn't this work?
Line 43, not necessary you are going to put a delivery office if the distance is greater
than K , besides that there is another bug that neither I don't know yet.
010
000
if you skip distance 1 cooridinate, you get answer 2. but it's 1 selecting the (2,2) point
1 2 3 010 000
gives 1?
https://ideone.com/cR0pXA
yes. your previous code gives wrong answer.
Can someone please explain that in second question in binary search function, how do we find optimal cell which can give maximum distance atmost K in O(RC). I could not figure it out from editorial. They said it is.
dist((x1, y1), (x2, y2)) = max(abs(x1 + y1 — (x2 + y2)), abs(x1 — y1 — (x2 — y2)))
How do we get this?
Consider the four corners of a box, the first term is "dist(top right, bottom left)", second term is "dist(bottom right, top left)". With the bottom left corner as (0, 0).
Since there are a few people PM-ing for clarification about the problem C editorial I think I might as well create a short summary here:
Why does picking the min order in the forward direction doesn't work
The issue here is that you are not doing dynamic planning here. While I can't give a formal argument in disproving if this approach is correct with some special tie-breaking method, I cannot prove it is correct either, due to the fact that min(jth request) is dependent on the subset available for the jth request. While it is guaranteed that the order shall generate less seats if they come later, you might not care about the decrease if K is significantly smaller than it.
If this is your first time dealing with min max stuff and you can't see why does such plan causes a bad K in the future, a problem that I would recommend on top of my head is "HDU 6000 Wash".
Why does picking max backwards works here
Before I continue I must clarify the editorial's approach as it is proven to be confusing to multiple readers.
Consider the corner test case provided by Errichto.
What the editorial meant by picking the max segment is that you must imagine that the other segments have been picked prior to the concerned request, for example, the first iteration would be:
[2, 8] : Imagine that [1, 4], [5, 8] has been occupied, and picking [2, 8] last must yield 0 seats.
[1, 4]: Imagine that [2, 8], [5, 8] has been occupied, and picking [1, 4] last must secure 1 seat.
We shall pick [1, 4] as the last request processed (we skip [5, 8] as an exercise for the reader).
On the second iteration, you will prioritize picking [2, 8] as it yields 3 seats. Note that you should imagine [1, 4] as not processed as you are considering [2, 8] as the 2nd request and [1, 4] is chosen to be the 3rd request, which is satisfied after picking [2, 8].
Now we may apply a similar argument: If the request was satisfied after processing only a set of request S, it must yield more seats as it would after processing the set (S union T).
As an informal proof, consider that the request i was picked on time j is the bottleneck of the ordering, i.e. it secures only k seats, let's see what happens if we attempt to process it in another time.
If request i swapped place with the request processed on time jg > j: It will then yield even less seats so the new k must be decreased.
If request i ... time jl < j: Note that we picked request i on time j because it yields the most seats at the time. Swapping it with any other picks must yield less than k seats on that iteration, resulting a worse allocation.
To generalize the proof above, one must show that k is non-increasing even for arbitrary swap. This is left as an exercise to the reader.
In the last line , did you mean non-increasing?
Ah yes, thanks for pointing that out.
Thanks. Your answer is crisp and clear. But after reading your answer, I still don't understand following in their editorial: "the number of unique ranges that the requests cover is at max 2 * Q, which would make our solution run in O(Q^2) for every test case." — From where did the factor of 2 come in 2*Q? I don't understand this line. Shouldn't the maximum unique ranges be Q if we are given Q queries?
I think "equivalence class" is a better word for "unique range". Whenever you add a new query.
For example, if you have [1, 100], [2, 101], and you add [3, 102], two classes will be cut by the new query, namely [2, 100] is cut into [2, 2] and [3, 100], and [101, N] is cut into [101, 101], [102, N].
I don't think I've seen anyone else mention it here, but the new "search bar" is incredibly laggy, and the lack of a friends list adds to the annoyance as it was there in the 2018 UI. I'm sure that a good number of other people feel the same way about these features...
My solution to problem B was O((RC)^2) and it passed the hidden tests. The key was to randomly order the squares with 0 before checking each of them. I didn't do formal math (just convinced myself with some examples) about this but it seems to work. Did somebody do the math?
My submission
Interesting. It sounds like you are using similar concept behind randomized trick Radewoosh mentioned?
Yes, you are right. Actually, I learned about this concept reading that post and I find it really interesting. I usually think about applying this idea when I don't find a way to improve the asymptotic complexity and I see that the worst case somehow depends on the order you process some data.
Would anyone like to point out what I'm doing wrong in my simple solution Problem B's visible tests? I feel like I'm following the analysis properly.
https://codeforces.me/contest/1141/submission/51800899
In this case the answer is 1 and your code gives 2 as result:
It is because the farthest point is not necessarily the optimal.
Could someone help me understand the editorial solution to the large test for C? I don't understand how we can quickly determine which seats are covered by exactly one interval. Is this operation provided by the interval tree, or does this need to be determined in some other way?
Do a parallel binary search on a min segment tree.
Analysis: The number of possible orderings of the requests is Factorial(Q), which would not be fast enough for either of the test sets. We can observe that for a chosen ordering of the requests, the number of seats that we can book in the last request does not depend on the ordering of the previous Q - 1 requests. Another observation is that at every step we can always choose this request greedily from the remaining set: the one where we can book the maximum number of seats.
I think it's not a right greedy approach to chose a request with maximum possible bookings of seats. Consider a case for 2 intervals: [1,4] and [1,2]. According to this approach[1,4] will be chosen first and then no seat for [1,2]. Hence ans=0 but in the opposite way, we can get ans=2. It is possible that I didnt understand what the statement means. If that is the case please let me know.
Since we are considering a query to be the last query in remaining set, maximum possible seats means the number of seats requested only by this query, as if a seat is requested also by another query, it would have been already given to that query. So, for 2 intervals[1,4] and [1,2], seats available to [1,4] is 2 and seats available to [1,2] is 0, so we select [1,4] as last query. Now, seats available for [1,2] is 2 and so we select it as 2nd last query/first query. And since both queries has 2 seats, our answer will be 2.
Can anyone explain in detail how the greedy approach in working in problem C.
Someone already did. Just read the comments.
Can someone post the Code(preferably Cpp) for second question that uses the binary search as discussed in editorial? I have cannon figure out how to calculate maximum distance from the location to a square in constant time for all locations that have greater than k values.
Here is what I did: first calculated distance of each node from the current delivery office using multisource bfs then do a binary search on the answer k. For a valid k, we have all distance less than or equal to k so adding a new position (let it be a,b) as delivery offices only affects the positions x,y within the rhombus: abs(x-a)+abs(y-b) <= k so you only need to verify that does there exist a point in which all > k current distance nodes are all inside the rhombus which can be calculated easily using maximum x+y, maximum x-y, minimum x+y and minimum x-y of all the points with distance > k. CODE : https://ideone.com/uBTBJx
Please explain this part in the analysis of problem B: "Hence, we can compute the maximum and minimum values of both x1 + y1 and x1 — y1 for all squares with a delivery time greater than K."
why do we need to compute max and min of x1+y1 and x1-y1? why do we want the distance of x2,y2 maximized?
I am having a hard time understanding the analysis :'(
For two points (r1, c1) and (r2, c2) we have four possible cases.
Now lets fix (1). Its equal to D = (r2 + c2) — (r1 + c1).
Also lets fix (4). Its equal to D = (r1 + c1) — (r2 + c2).
This means that case (1) and case (4) is equal in absolute value. These cases stand for the first term in the tutorial. With similar method you can take that (2) and (3) stand for the second term in the tutorial.
So if we use abs() we don't have four cases but two cases. The team of (1)-(4) and the team of (2)-(3). Also the real distance is the maximum of these. You can convince yourself with an example, because if you use the 'wrong team' it will give you less than the real distance. So taking the max() of these is optimal.
Now that we are convinced that the formula works, between two points (r1, c1) and (r2, c2), if we build an office at point (r2, c2) we would like to iterate over all other points. But for every pair of points we will use the same equation. Each term of the equation is of the form:
T = max(a — b, b — a). (because of the abs())
So if we have fixed 'b', isn't better to take 'a' as large as possible or as min as possible ? Intuitively we want 'a' to be as far as possible from 'b'. So having the minimum and the maximum possible 'a' is enough, because for EVERY 'b' its always better to pick the maximum or the minimum 'a' rather than one in between (you can visualize it with a line).