Hello everyone!
This Saturday May 20, 21:05 MSK rated Codeforces Round #415 takes place.
As for our previous round 384, the problems were set by Kiril kefaa Gulin and Yura hloya_ygrt Shilyaev. And this time Daniil Melnik Melnichenko joined us! Many thanks to coordinator Alex netman Vistyazh for help in preparations of the round, and also to Mike MikeMirzayanov Mirzayanov for Codeforces and Polygon systems.
While everyone is waiting for second half of "SKAM" series season, we offer you to solve problems, main characters of which would be stunning girl Noora and well-known to you from 794F - Leha and security system hacker Leha!
As always, participants of both divisions will be given 5 problems and 2 hours to solve them. Scoring will be announced before the round.
We hope you'll like our round! I wish everyone good luck and high rating!
UPD: Please pay attention that round was rescheduled.
UPD2: Scoring in each division is standart 500 — 1000 — 1500 — 2000 — 2500
UPD3: We are extremely sorry about the issue with problem C, but since it affected not many participants, round remains rated. At the same time, we can remove your unnecessary submissions and if you were affected, we can make round unrated for you. Please contact KAN with this question.
UPD4: Congratulations to the winners! Editorial will be posted tomorrow.
Div1:
Div2:
UPD5: Editorial is available http://codeforces.net/blog/entry/52099.
What about the reschedule? http://codeforces.net/blog/entry/52009
edit: nvm
Round has been rescheduled to another time.
Why isn't this on the front page ???
UPD: nvm fixed
Very very unusual start time !!! Too bad :(
that's right, in our country it's in 1:05 am
Duration will be in the middle of night in east Asia, Will u stay up and burn the candle at both ends?
same here..participating anyways :D
The start time is 2 am. it's so late. participating anyway...
...
Hope the contest will enjoyable, and spending night time for the contest will successful. :)
participants were few in these last contests. in the usual cf time, there had been like an average 6K participants.
btw there are some people who cheat in the contests. Like the guy who hacked 40 times in the last contest (hacked the same person). there should be consequences for people like them.
that guy was disqualified :)
(didn't know it till now as he was disqualified after the ratings change). he had a 397 up as far as i remember.
what a beautiful thing, what is it? :|
A Slowpoke.
Cheating contestant should be transformed into this thing.
MikeMirzayanov IF CF is down for today and round is gping to be unrated.Plz make Update before such things happen.
CF server looks ok now =D
Hopefully, it'll stay like this throughout the contest. And it would be really awesome if they can show the standings and the ratings change really quickly. It's already late in my region. :(
I was wondering why the site wouldn't allow me to register for like 5 minutes and then I realized I was currently in div2 lol :D :D
Another contest from Belarus :) Hope not be same as tourist's contest, that was veryyyyyy bad
Maybe instead of complaining you can practice both English and competitive programming?
Can you explain what is wrong with english????
15 minutes left. When is the scoring announced?
Maybe when the contest starts :D
UPD : I was wrong.
I dream there will be a day when my rating skyrocket to the moon just like bitcoin price :)
P.S. Bitcoin just became candidate master at 1980.
Does the rating predictor extension not work anymore?
https://cf-predictor-frontend.herokuapp.com/roundResults.jsp?contestId=810
shows nothing.May be its down or not working
Sorry. It will be fixed before next contest.
Russian Code Cup #2.... :'''))))))) (Not 100% sure it will pass though)
EDIT: It passed.
Congrats!
Thanks :)
Congratulations! You passed it :)
How to solve Div2-B?
let add[i] be how much we can add if make a sale in day i. add[i] = max(0, min(l[i] — k[i], k[i])). Then to sell as many items as possible we just sort add and take f biggest values
find out the added profit for each element if k is doubled using profit = final — initial where intial = min(k,l) and final = min(2*k,l). now sort these profits and take the f maximum values since you want your answer to maximum. code :- http://ideone.com/yDxz6l
A[i] : Number of Products that can be sold if not sell out day. B[i] : Number of Products that can be sold if its a sell out day.
C[i] : B[i]-A[i]. Sort C. Final answer will be Sum(Array A) + F Highest values from C.
After sorting array for (Math.min(2*k,l))-(Math.min(k,l)), we take first F elements with sell-off, next without it.
what if we keep a vector having min(2*k,l),min(k,l) as pair and sort this vector.For first f values we can add first to the answer and for the rest second? what goes wrong with this approach ?got wa in tc 15.
You should sort pair by value of difference beetween min(2*k,l) and min(k,l). My Java code of sorting:
How to solve Div2 C?
http://stackoverflow.com/questions/30139399/finding-sum-of-the-differences-of-max-and-min-of-all-possible-subsets
I found this problem really similar to Kickstart Round B 2017 PROBLEM A
The only difference being you could solve Kickstart problem in O(n^2) complexity but not this one.
So basically people are rewarded for just Googling the problem instead of trying to solve it for themselves? That's just stupid...
well, i didn't googled it, i participated in kickstart round B, but i agree with your opinion, its stupid!
There are problems which use the same set of principles.
This problem belongs to that set.
You don't need to google in order to solve it.
Whats wrong with my submission 27246547? I folllowed the idea above, but I got TLE... :-(
In java for Arrays.sort you should use non-primitiv type, so you need to change long to Long:
Also change nextInt() to nextLong():
https://codejam.withgoogle.com/codejam/contest/11304486/dashboard
for each i sum += 2i * ai — 2(n - 1 - i) * ai
I did the same but it was failing
You have to use mod power O(log(n))
https://pastebin.com/ghBYxEbD
This is my code . Can you tell the mistake?
line 47: (index(i) — index(n — 1 — i)), index(i) could be less than index(n — 1 — i) under the mod
pro += (index(i) - index(n - 1 - i)) * (a[i] % mod);
`` This seems to be wrongit should be:
pro += ((index(i) - index(n - 1 - i)+mod)%mod) * (a[i] % mod);
``as (a-b)%m = (a-b+m)%m;
Oh..okay ..thanks for help nimxor and eagle93
That's not necessary. It's simpler to just precalculate all needed powers of 2 modulo 109 + 7.
when you write down the subsets and calculate a few values then you will notice a pattern that is highest value never gets subtracted and lowest value never gets added in answer. sort the array lets say a1,a2,a3,a4. now ans is a4-a3 + 2*(a4-a2) + 4*(a4-a1) + (a3-a2) + 2*(a3-a1) + a2-a1. derive this in terms of n and now make a table and note down how many times each element gets added in total and subtracted from total. you will notice that in sorted order element at index i gets added 2^i — 1 times (0 indexing) and gets subtracted 2^(n-i)-1 times. now you can simply iterate in the array and find answer taking care of mod. code :- http://ideone.com/4b4koZ
Please, may you explain deeply?
Wow! Am I the only one who is stupid enough to use segment tree in Div2.C? 27247380
yes
Someone tell a clean approach for Div1B? It was easy to find position of one of the ball. But i couldn't get for finding other...
Also, i expect lots of system failures (including mine)
Accepted Solution:
If the position of the first ball is X, then I searched in the same way for the second ball in 1 => X — 1 & X + 1 => n
getting wa with same approach :/
Did you ask if the leftAnswer is better than the rightAnswer or not at the end.
Yes I did the same, I also compared the leftanswer and right answer in the end. Still WA
http://codeforces.net/contest/810/submission/27251869
printf("1 %d %d\n",l+1,r+1);
I don't do that. I just compare the mid with min(mid+1, hi) to know if I should search to the left of the mid or to the right of it.
What Was pretest 11 div 1 B
I have wrong answer at it also. I found this test make my code fail 9 3 (2,4,8); I corrected my code and I waiting now to resubmit it. I don't know if it is the test or not.
Are you insane? This round should be definitely unrated. At least for div.1
i performed badly hope so your words come true but whats the reason ??
ROUND SHOULD BE UNRATED FOR ALL. MikeMirzayanov
Why is that?
First tell me why are you using fake account
The only reason to make the round unrated would be the need to rejudge Div1-C/Div2-E but, now, it has been announced that they can make it personally unrated for you if you have been affected by this issue. So, yeah... I can't see why this round shouldn't be rated.
We can make it unrated for participants that were affected, if they ask to.
Just out of curiosity.Are u gonna make ur round unrated??
Well, if I had +X rating it will be not fair. Since I got -6 it is OK.
If authors say that spending 17 minutes trying to find a bug in AC code is OK then it is probably OK.
Yeah in ur case U might have got AC on 2nd question if u had that 17 minutes time.
IMO the difficulty is: A <<<< D <<<<<<<<<<<<<<<<<<<<< B,C << E
B was easy only once U get the idea of binary search
How could you do binary search? I thought bsearch as soon as I saw the constraint 60, but I couldn't make any ideas about it.
We can binary search as if there was only one ball, and find a position x where we know that there is a ball.
Then we can repeat the same procedure, but this time instead of searching over the region [1, n] we search [1, x - 1] and [x + 1, n].
Edit: They are dishes not balls, but same idea :D
Could you tell me how to "binary search as if there was only one dish to find a position x"?
EDIT: They are dished not balls xD
At every iteration in our binary search, we query
1 mid mid+1
. Based on the answer, we know whether we need to look to the left or to the right for the closest dish, and setlo = mid+1
orhi = mid
accordingly.Although this does not find the leftmost dish, it is guaranteed that this will give the location of one of the dishes. To see why, notice that there will always be at least one dish in the starting interval [1, n]. At each iteration of the binary search, the closest dish might change, but there will always be a valid dish in either [lo, mid] or [mid + 1, hi]. If we receive
TAK
for our query, then we know that there is a dish in the left interval, because if there wasn't, then there must be a dish in the right interval, and the query would have givenNIE
. The same logic applies for choosing the right interval if we receiveNIE
. Hope that helps!P.S. This approach is correct: 27248627
I did the same as u have said. What is wrong with my code.Gave WA in pretest 11 http://codeforces.net/contest/810/submission/27252700
If you query (x, x+1), there definitely exists a dish at position <= x if ans is TAK and there exists a dish >= x+1 otherwise. Using this, keep querying (mid, mid+1) and find the position of the first dish. After that check if there exists a dish to its right and use the same procedure on some particular interval on its right. Otherwise do it on the left.
Wow..... I thought the idea of querying (x, x+1) but never imagined to do binary search with that. 160 people who solved B must be geniuses!
U can check here.
I tried to first find one of the dishes by always taking that half which has closest dish(since it is guaranteed to have a dish).
let it be k.
Next again do same think for segments (1,k-1) and (k+2,n) and check for cases k-1,k+1,k+2 manually
The first observation you can make is that, if you assign a value to each dish, you will have an array D, where D[i] == 0 iff there is a dish he ordered. In addition if you imagine the graph, you are looking for 2 minimums of the function f(i) = D[i].
Now you can binary search to find this minimums, if after a query the answer is TAK, it must mean there is a minimum to the left, in the same way, if the answer is NIE there must be a minimum to the right.
Even though idea on D is easy, splay tree was not a common subject for me (and most coders, I guess) TT
I first googled for some splay tree resources, but soon I gave up and wrote N^1.5 solution
How can we solve D with Splay Tree? I'm not sure what the easy idea is.
Me too. Actually this was the first time that I used the splay tree. I went to http://cubelover.tistory.com/10, copy-and-pasted, modified a little, and debugged and debugged and debugged. Really wanted to give up, but B and C were far harder, so....
What is wrong with my div2C solution ? http://codeforces.net/contest/810/submission/27252345
Your mod is 1e9+9 while it should be 1e9+7
It doesn't matter. My previous submissions had 1e9+7 and still didn't pass
maybe sum < 0 ! sum=sum%mod;
sum=sum+(x[i]*(modular(2,i,mod)-modular(2,n-i-1,mod)))%mod;
should be
sum=sum+(x[i]*((modular(2,i,mod)-modular(2,n-i-1,mod))+mod)%mod)%mod;
As (a-b)%m = (a-b+m)%m;
as a-b can be negative also
Also mod value should be
1e9+7
Take array 1,2,3. Sum is 6 and it is ok when module is negative.If i change it to be always positive it will output 9 which is not correct
no it gives 6 only.
which comes out to be 6 only when added
You shoud take mod with 1e9+7 not 1e9+9 as I said earlier. You are repeating the same mistake.
I'm sorry, my bad, but still my solution gives correct answer. :((
I think the negative from
Screws up the modulo.
CMIIW
(modular(2,i,mod)-modular(2,n-i-1,mod) this line can be negative so should do:
(((modular(2,i,mod)-modular(2,n-i-1,mod))%mod+mod)%mod
Consider array 1,2,3. it is -3*1+0*2+3*3 = 6 which is correct. So it doesn't matter i guess
nono, I mean given i < j, 2^i%mod can be larger thak 2^j%mod.
EDIT: imagine if one is 1e9+8, and the other is 1e9+6, the substraction would dive -(1e9+5) instead of whatever value you would need.
modular(2,i,mod)-modular(2,n-i-1,mod)) can be negative also and you cannot perform (negative numer) % mod which leads to wromg answer. you need to add multiple of mod to it to make it positive before applying mod opertion
Look above, tell me if i'm wrong.
I did not take care of negative modulo but passed the pre-tests. Do you reckon my solution will pass sys tests? I mean I'm pretty sure that negative modulo case would have occured in the pre-tests. How did it pass?
It must work with negative module. And i don't know why it didn't pass.
Div.1 D is quite similar with APIO 2016 Boat, or is it not?
The idea itself is completely different, but i was inspired by APIO task when thinking about my own one.
How do you solve Div1 B?
I'm pretty confident of the following solution.
The amazing trick is to always let a + 1 = b whenever we query. Thus, this gives us the following information: "there is a dish closer to the left" or "there is a dish closer to the right".
We are able to find the first dish this way. We perform a sort of "binary search" on the range [1, n]. Each time, we will query two consecutive midpoints m and m + 1 (where m = (l + r) / 2 as usual), then if it tells us there is one closer to the left, we go to [l, m], otherwise [m + 1, r]. Once the range has been compressed to 1 or 2 elements only, we will have found one dish.
The second dish can be found similarly. Let x be the location of the first dish. Then, we will perform two separate binary searches like the one above: [1, x - 1] and [x + 1, n]. The amazing thing here is that the first dish x will never conflict with any dish in those ranges; that is, if a dish in either range exist, our binary search will find that and not x.
We start with [1, x - 1]. If the answer to the queries is always , and query [x - 1, x] is also , then we will know, that there is no dish in the range [1, x - 1]. Thus we can find the dish in the other range.
Overall this takes queries which fits comfortably in 60 queries.
I did exactly as you have mentioned. Can you pls point out the mistake in my code. http://codeforces.net/contest/810/submission/27252700
I was doing this but wasn't sure about the conflict thing :(
Missed submitting the Div. 1 C by 1 minute... horrible feeling ever! :(
Hope you will get WA :)
Wasted too much time, could not spot this bug
n && (1LL << k)
instead ofn & (1LL << k)
.Such silly mistake cost me like 20 minutes >_<
Maybe it will be easier for you when I say that once I had p ! = x, instead p|=x. I spent more than 15 x 15 minutes to see it :)
I am depressed
My mom is psychiatrist, so do not worry again :D
Can you explain how to do it.
I thought like we can subtract one from all then a[i][j]=i^j.
Later I thought like f(x1,y1,x2,y2)=f(0,0,x2,y2)+f(0,0,x1,y1)-f(0,0,x1,y2)-f(0,0,x2,y1) something of this sort. But i couldnt compute f function.
Is this the way to proceed.If not whats ur approach??
How to solve div2 C without using double for, which gives TLE for sure? :(
see this
Problem C:
I know that I placed a mistake somewhere OVER 9000 formulas. I know the WA test. I could not find in within 20 minutes of debug.
Shit.
what is wrong with my Div2 D solution. I used Binary search to first find the 1st dish(let's say k). Then I applied Binary search on 1 to k-1 and k+1 to n to find another solution. http://codeforces.net/contest/810/submission/27252700 The code gives WA on pretest 11.
U should'nt do binary search from k+1 to n.U must do from k+2 to n And check for cases k-1,k+1,k+2 separately(this separate cases bcoz equality gives tak)
If I say that a is first ball, then if second ball is little greater than middle of a+1..N then there is a chance that I get TAK, TAK, ... again since a+1 is closer to a and I miss the correct ball which was in middle and shift my range wrongly?
Could you please clear my question?
Yeah kind of similar thought since (x+y)/2 is always closer to x than y. So your thought process is right. There is chance of missing some point
I believe for B div 1 better option was asking for one dish and having score 750 :)
Is intended complexity of E O(n * log(n) * 35)?
BTW, I was using Wi-Fi of Rushmore Plaza but in the last 30 minutes it started not working. So I couldn't do anything. Is there anyone having same problem?
You can improve that to O(n * log(n) * (2 ^ 5) * 5) (or simply O(n * log2(n) * 5) because sum of x 2 ^ d(x) is n*log(n)) by doing some dp trick
I have an solution.
I passed it with . It actually should be less but I could only prove an upper bound.
Great work!
Intended solution has complexity .
Till the editorial is not published, everyone can look through the author's solution 27254027 :)
Am I the only one in the world who doesn't like interactive problems :\
no
They should mention in the blog that there are going to be interactive problems at least. -_-
We wanted to, but as it wasn't noticed in VK cup round 3 announce, we decided not to do that.
http://codeforces.net/blog/entry/49376 had it so I thought it was always announced. Nvm then.
Why should they?
Because some people don't know what an interactive problem is.
Do you realize how stupid this actually sounds? Some people will never know what a DP problem is, should this be announced, too? It's been a long time since interactive tasks were introduced by CF, not to mention that the statement makes everything clear.
I don't think that your comparison is valid, you compared an algorithm (dp) to a technical term ( interactive problem, you should know about flushing, which has nothing to do with CP )
I don't see how that matters. Flushing has nothing to do with CP? Not sure how you define "has sth to do with CP" but many things had nothing to do with CP until they were used for first time. And even "you should know about flushing" is wrong since the statement tells you what to do. I will once again say that this type of problems were introduced a long ago and the announcements of the first few rounds which used them had a link to the detailed guide.
I am sorry .But do people prepare any template or anything for interactive problems??
No, they should prepare Aspirin :D
Something like this does the job for me:
Nope, I just don't like them so I tend to avoid the contests that have them. And I guess there are a lot like me.
It usually sucks when authors put boring stories thinking this will make statements more interesting. But it sucks a damn sight more when their English sucks as much as the stories.
can this problem be solved?
shift [l,r] to right
add to [l,r] 1
q,l,r <= 1e5
Shifting is just erasing element at position r and inserting it before l. I think it can be done with sqrt decomposition.
How?
it is easy to solve D1 with this problem
Yes, it can be solved with the help of the data structure called treap. Furthermore the complexity will be about logN on one query.
Can you please explain your approach.
I hope, these two articles and my code may help you.
Aren't the value of cells equal to abs(x-y)+1 if((x+y)%2)==0 and equal to x+y-1 otherwise where x and y are the row and column number respectively. I m talking about DIV 1C /DIV2 E
They are equal to (x — 1) ^ (y — 1) + 1
all the diagonal(1,1 to n,n) elements are 1. it does not satisfy.
Why? For each a, a^a is equal to zero. So, this condition is statisfied.
i thought ^ is pow. my bad thanks
Apart from observation, does there exists any way of proving it?
Yes, It is equivalent to calculating grundy numbers for a two pile nim of sizes (i-1) and (j-1) and adding one to it.(Nim idea comes from fact that we are taking mex of row and column )
Thanks, got it
Can somebody explain me, why in B there were "TAK" and "NIE" ("YES" and "NO" in Polish)?
It is not fair, you had advantage at the beginning :P
Maybe it's cultural appropriation :)
3/3 authors and coordinator are from Belarus and this words are the same in belarussian language. Also we are fans of main.edu.pl site and already get used to such answers to queries. :)
Waiting for system testing to start ...
problem C (Do you want a date) link : https://code.google.com/codejam/contest/11304486/dashboard I have submitted the same solution.
That contest is old (from 2017) so probably nobody who took part of the contest remembered it...
Sorry about that, but we proposed our contest much earlier than kickstart 2017 happened.
but how this justifies to keep the round rated as more than 50% of DIV1 people soved only 1 problem which is same to an old problem.
Waiting for System testing
How to solve Div1 C? I only found that dat[i][j] = ((i-1) ^ (j-1)) + 1.
I couldn't solve it yet so don't take this as a solution but probably you have to solve 4 queries that are query(1,1,x2,y2) — query(1,1,x1-1,y2) — query(1,1,x2,y1-1) + query(1,1,x1-1,y1-1) and then solving queries with x1 = y1 = 0 is easier.
Then you can see that there are some squares (of sizes powers of two) that can be calculated easily, but I don't know what happens when the area is too big in one dimension but not in the other one, probably there's something to do with some rectangles that I couldn't calculate but I don't know.
You can calc answer for query(0, 0, x, y, k) with dp (code will desribe it better than words): 27247417
We will solve the problem for queries with x1 = y1 = 0, it's obvious how to solve the actual problem afterwards.
Notice that you can create the grid by starting with a 1x1 cell with a 1 in it. Then, to go from size 2k to size 2k + 1 you take four copies of a 2k grid in a square and add 2k to all values in the two 2k cells on the antidiagonal (you may want to print the grid for small values to visualize this).
We can use this generation process in reverse: initially the query is contained in a square of some size 2k. We can split it into four subqueries on grids of size 2k - 1. Specifically, if we are querying for ((x, y), M) (where M is the upperbound) on a grid of size 2k, then this is identical to adding together the following four subqueries:
This recursion is quite expensive, but it turns out that in a lot of cases we can directly compute the answer. We can also see that the square of size 2k contains all numbers from 1 to 2k, each 2k times each. So if x, y ≥ 2k, i.e. we query the entire square, we can simply add 2k times each of 1..min(2k, M) to the answer. For the case when only one of x, y is larger than 2k you'll have to think a little harder, but that too has a closed form solution.
Finally, note that when coming out of the recursion for subqueries on the antidiagonal (where you subtract 2k from M), you actually have to add 2k to the answer for each number that you added 'down there'. So not only should you return the sum of the query from your recursive function, but also the amount of numbers in the sum.
EDIT: Here is my accepted solution. It contains some idiosyncracies, I'll post a more compact solution once upsolving is possible.
EDIT2: Simpler solution.
Thank you! Far better explanation than editorial!
Rating of most of the DIV1 users will change on basis of one question today which u can find by googling moreover it was a recent problem so many of the DIV1 users must had participated in that contest too which gives them a super edge over others. This is just not right for CF :(
please start system test.
I was cheated by the "int".....Though it was hacked for some other reasons. someone's solution for div2/C
What was the hacking case for DIV 2B?
I hacked your solution with this test:
2 1
3 10
50 51
I got it! Had the algo but wrote a buggy code! :( ans for this is 56, right?
Yes :)
So what is test 47 in D1 A?
I feel like it must be something bizarre, because running my solution locally against Lewin's on randomly generated cases there is no difference. If anybody is bored here is my submission, 27240358, I can not for the life of me figure out why it is wrong.
Could it be int overflow? (Edit: scratch that, looks fine)
I see your solution as running on test 1
Yeah it seems it is being rejudged. But it originally showed for me as "Wrong answer on test 47".
Oh now it shows the issue as: "Can't find file C:\Contesters\Work\invoker-prod\work\codeforces2\4375ab888520facceff67c17abfbd1cf\check-e1271c8a6a57f31648a43d4032fc0bbe\run\output.fd0138e687.txt."
On test 47. WTF.
Maybe it is tested on WinXP and the output got encrypted?
Hm yeah I have no idea. But it got rejudged as AC thanks to hloya_ygrt :)
System tests seem to have started and paused...
system test like
Is that an IQ-test?
I don't understand. What does it mean?
Yeah, I googled that image. It means "to be continued".
For Div2 D,
First I applied binary search. Stopped the loop when both left and right pointers became equal, that was 1 of the ordered dishes, say k.
Then I applied binary search from 1 to k-1, and k+1 to n. At least 1 of these segments had an ordered dish, so finally queried once for the answers obtained in the above 2 binary searches.
What is wrong with that?
Code
Anyone knows why I'm getting WA on test 15 Div2 B?Solution(yes I know my solution is a total overkill...)
I think what is wrong with your solution is the following: you have to check in the for at line 55 if you have already used the products for that index, because sometimes 2 * products_i could be less than products_j for some i,j, let me know if you need a more detailed explanation
Will ratings be updated today or we'll have to wait until the problem with the people who wants to be unrated is solved?
What is the meaning of N=1 in C. Do you want a date?
There is one subset, {x}, maximum distance is |x-x|=0.So, answer is zero.
Div 2C/Div 1A. Test 69 doesn't accept java's Arrays.sort. So frustrated...
Arrays.sort uses modified QuickSort (which is O(n^2) in worst-case) for primitive types. So I don't know how hard to create worst case, but test#69 obviously that case.
On other side, Arrays.sort uses TrimSort (which is O(nlogn) for worst-case) for objects. So all you need to do is change x from array of ints to array of Integers.
BANG BANG!
Congrats!!
Congrats man!! Back to LGM :D
Tasks with polish words in statements && Radewoosh wins.
Coincidence?
Don't think so
illuminati confirmed
Will div2 rating going to update or not?Its too late
Still waiting......Div 1 ratings already updated...this time too late!
Ratings are updated now.
Hi,
Can you please help me understand why the following solution exceeds the time limit for div 2 problem C: http://codeforces.net/contest/810/submission/27252557 ? It seems like most accepted solutions have the exact same approach.
Thanks
People have been complaining about Java sort: http://codeforces.net/blog/entry/52092
So, what happened with moejy0viiiiiv and jcccccccccccccccccccccsb?
Edit: never mind, they probably requested to be excluded due to the issues on problem C.
Hi! In div2 C, I did exactly what I am supposed to but it didnt pass. Can anyone help me please. http://codeforces.net/contest/810/submission/27247180 ____I don't understand whats wrong with this.
iter *= 2 should be by modulo http://codeforces.net/contest/809/submission/27262433
Danm man! I could have got it correct. Thanks a lot.
editorial?
Waiting too……
Excuse me, where is the editorial?
Hey friends,
I was trying to solve problem C of this round in C++, but I've just been getting 'wrong answer' on test 6. I get right answers when there are small values to deal with, but when the numbers get bigger, like in test 6, things go wrong. I feel like the algorithm itself is fine, but I'm not handling the data properly. I'm also new to C++, so that's totally possible. I tried a lot to fix the error, but nothing seems to work. Anyone out there to help me out? I would really appreciate it. Here's my code (http://codeforces.net/contest/810/submission/27260339):
include include include
using namespace std;
int main(){ long long mod = 1000000007;
int n; cin >> n;
long long arr[n];
for (int i = 0; i < n; i++){ cin >> arr[i]; }
sort(arr, arr + n);
long long ans = 0;
for (int k = 0; k < n; k++ ){ ans += (long long)((pow(2, k) — 1)*arr[k]) % mod; ans -= (long long)((pow(2, n-k-1) — 1)*arr[k]) % mod;
} cout << ans%mod << endl; }
This is an overflow issue. You have to typecast the variables inside the brackets, that is, before the multiplication. You are typecasting them after the multiplication.
A short trick for this to avoid writing
long long
everywhere is to just multiply1LL
to the expression which might cause an overflow, which makes the execution of that particular expression in 64-bit.1LL
is an inbuiltlong long
1.Can anyone say what is wrong with my solution Div 2 B
(http://codeforces.net/contest/810/submission/27260753)
People often get WA16 because sorts Math.min(2*k,l), but it should be sorted by difference between Math.min(2*k,l) and Math.min(k,l). So you need sort increasing of profit.
How to solve div1 D better than O(n sqrt n)
I'll write it here too :) You should use a special data structure called treap. You can read about it somewhere on the Internet (I don't know sites on English, which can help you to understand this data structure) or just look at my code.
How to solve it in nsqrtn?
The task can be reduced to some queries on an array:
delete one element from the array
add one element
increase all elemets [l,r] by 1
shift segment [l,r] to right
So sqrt-decomposition may help you to process these queries. And if you want to understand, how it can be reduced to such queries, please, wait the editorial. It will be published in a few hours.
A great contest for me! +228, Rank 42 :) It is always 42 indeed! :)