# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Name |
---|
How to solve 250? Also, why is the logic of sorting in increasing order of B/A ratio incorrect for 500? All solutions in my room got hacked because of this.
About 500:
Try this test
{3, 1}
{2, 1}
1000
It's better here to do {1, 1} first, and {3, 2} second.
250: I pictured it as if it was a directed graph with edges i -> a[i]. I've found all vertices reachable from 0 and 1 by following those edges, let's call those A and B respectively, and their common part C.
If C is empty then 0 and 1 are in different components at the beginning, and we need to choose at least one vertex from A and at least one from B, and all such choices are good. If they have some common vertices, then a choice is bad only if we choose some vertices from C, but they will all be in A \ B, or all in B \ A.
So in both cases it's a simple formula depending only on size(A), size(B), size(C).
500: Both halves must be sorted according to this criteria, but not the entire array. If there are just two elements then it's optimal to sort them according to something like B/(A+X).
Can you explain what does
A\B
signifies?B/A means that we sort the positions on the basis of the ratio B[i]/A[i], for each i.
I think you misunderstood my question. I'm asking about 300 points problem. krismaz's line states "If they have some common vertices, then a choice is bad only if we choose some vertices from C, but they will all be in A \ B, or all in B \ A.". I couldn't understand latter part. (
A\B
andB\A
)It is a set difference (see link). It is a set, which contains all elements from A, which are not in B.
Oh thanks. That notation was new for me.
A\B means set difference. The A\B set contains elements that are present in A but not in B.
Passed B with 60 million state DP :D
I am interested to hear the actual solution though, I saw jqdai0815 use a 3-dimensional DP but I couldn't understand it.
I don't know if this counts, but here is an idea.
I had a 4-dimensional DP (total numbers passed; number of people in the first half; sum of B in the first half; sum of B yet to be taken in the second half) with (N / 2 * maxB)2 * N * N / 2 = 78m states.
The starting points are (0, 0, 0, S) for all possible S. Therefore you can track through S in the outer loop and have a 3-dimensional DP with the same complexity.
If I'm in a state, how do I know which projects can be taken and which have already been completed?
Is there a greedy solution that works if there were no training camp? (Edit: tunyash says yes and I will try to figure out why)
Yes. You sort all the states by a[i] b[i]. The proof is based on the fact that if you compare gains you get by processing a[i], b[i];a[j], b[j], as opposed to the opposite order, as two last elements, they are exactly equal to C + a[i] * b[j] and C + b[i] * a[j] in the other, irregardless of what experience you had before that.
That makes sense, thanks to you and tunyash for your explanations.
Sorry, saw your comment only later. But how then did you then solve the problem without fixing the order of numbers?
10-dimensional DP on:
The worst case is 5 people with each value of b[i], which gives 610 ≈ 6·107 states.
First of all if X = 0 we should sort projects by a[i] / b[i] and in each half that order is the best possible.
Let's fix B sum of b[i] in the second half. Then dp[i][j][k] — the best possible amount of money with j projects in the second half, b[s1] + b[s2] + ... + b[st] = k where s1, s2, ...sk is the set of projects in the second half. Then if we put i-th project to the first half we should increase answer by a[i]·(B + b[0] + ... + b[i]) and something similar if we put i-th project to the second half. Then the answer with fixed value of B is dp[n][n / 2][B].
That fastest solution to div1 500 by totsamyzed made my day :)
I wonder if it can be challenged within the given constraints. I constructed a test where you would need on average N2 / 4 swaps to get to the optimal state from the random one, but this attempt at failing it failed:)
Couldn't understand what's wrong with my answers in 900 during the last two minutes, and now I got it; I thought there should be an intersection of rectangles but statement asks to make a union of them. I'm crying.(
Despite the fact 500 fell, I'm still going up! :)
Cool bug in 500: you should change i to i1 in one place. :) That's what happens when you forget about sort in the first place.
How to solve 500? Did anyone succeeded with something like simulated annealing?
Yes, see the aforementioned solution by totsamyzed. Although, I believe, it is simple hill climbing.
Yes, I also did it. I use something like gradient descent and pass system test.
Repeat following procedure for about 10 times:
First, sort all elements by
b_i/a_i
Repeatly about
10^5
times: randomly swap one from first half and one from second half. Then, sort first half and second half byb_i/a_i
again. If the resulting list is better then take it to replace the original one.From the last 3 contests there has been one problem each, that can pass system tests using random_shuffle :)
Wow so popular :)
How to solve div2 1000?
In my room I saw a guy who just hardcoded sums for each of i * 1e7 up to 1e9 (100 numbers), then summed up values from (n / 1e7 + 1) to (n) and added this numbers. It passed :P
I don't know how to solve the following problem. With solving the below I would be able to solve d1-hard, but maybe my approach isn't a good one. So, maybe the following problem doesn't have a solution.
You are given n (n ≤ 106) integers t1, t2, ..., tn (0 ≤ ti < 230). For each of n2 pairs of numbers we take their bitwise or (in code it would be
t[i] | t[j]
) and we find the first bit set to 0. For each of 31 bits count for how many pairs we found this bit.Do you see how to solve it? Maybe incl-excl principle?
Why 230? There are only 26 possible answers, and this can be solved in 226·26 (forward pass — compute Di, mask = count of tj so that tj is submask of mask and the last i bits are identical to the bits of mask, backward pass — compute di, mask = count of ti, tj such that ti|tj is submask of mask, the last i - 1 bits are 1 and i'th bit is 0).
But 226·26 is almost 2 billion, and I sincerely hope jury's solution is much faster (otherwise this is rather evil).
It's 26 indeed, sorry.
I think and hope that O(2k·k) is too slow here.
My 2^k * k implementation passes =)
http://puu.sh/paG0G/b57485addc.png
well you can speed it up by considering the primes only — you will have 6 (1, 2, 4, 8, ..., 32) * 4 (1, 3, 9, 27) * 3 (5, 25), 3 (7, 49 :D), * 2 ^ 13 states which isn't much and you could apply the same idea. this is about 27 * 2 ^ 16 states
mask means the state which we are in
dp[mask][i] = the sum of cnt[other_mask]'s which other_mask has the same numbers from the last 17 — i primes and its first i primes are more than mask's
The backward pass is only 227, so we just need to solve problem "given ti, count number of submasks of a mask among ti for all 226 masks" faster than 26·226. Not sure about the general case, but in this particular case, there is a structure on ti induced by the problem — subrectangles of a rectangle correspond to submasks. So maybe this can be solved with a careful counting of subrectangles (which seems painful).
(btw, where are topcoder problem editorials located nowadays? I wanted to see what's the jury solution for the problem, but finding it turned out surprisingly difficult)
link to editorials
they aren't uploaded immediately after the round. We must wait a bit.
I spent majority of challenge phase trying to hack specific code and when I finally got test it was rejected because I inputted numbers separated by commas and spaces however I shouldn't have spaces there and when I was getting rid of them that code was challenged >_>. Screw you TopCoder >_>.
Think positive: at least you're not getting Internal Server Error.
When do they post the editorials on tc site ?
div 2 1000 anyone?