*What is better than setting one AtCoder Grand Contest? Setting two AtCoder Grand Contests, of course!*

AtCoder Grand Contest 020 will be held on Sunday (time). The writer is tourist.

This is the first contest of 2018 counted towards AtCoder Race Ranking. If you get into top 30 in this contest, you will get GP30 scores.

The point values will be 300 — 500 — 700 — 1100 (500) — 1400 — 2100. Note that the contest duration is unusual (130 minutes).

Let's discuss problems after the contest.

I spit on u, go outside

u do not know da wae

What is better than setting two AtCoder Grand Contest? Participating in two AtCoder Grand Contests held by tourist, of course!Previous AGC set by tourist was 4,5 months ago, it's kinda hard to believe but these two AGCs are two AGCs

in a rowxD. Glad to see AGCs coming back (next one is scheduled three weeks after this).Isn't the next one three weeks after this and not two?

Indeed, thanks for nice catch, I will correct it

Pls kill me, I forgot about it and slept too long >_> Moreover before changing timezone AGC was always at 2PM, but now it is at 1PM, so it was 13min versus 1h13min being late in my case xd

Hm so the takeaway here for me is that you sleep past 1pm. Impressive.

1pm? These are rookie numbers

Judging from your personality, I thought you were trying F.

Score for D: 1100(500) means? is 500 partial score like in Codechef?

1100 (500) means that the full score of problem D is 1100, but it's possible to get 500 points for solving the problem for partial constraints mentioned in the problem statement.

It is unfortunate, I wasn't able to submit in last 2 minutes, page just didn't want to load :( You maybe should have extended the contest for 5/10 minutes because of such issues.

What is the solution to problem F?

I found the solution to the case where all L's are equal here, but the obvious generalization to the case where L's can be different was incorrect.

Uploaded the editorial.

Thanks. I've already seen it. By the way, why is there no subtask for solving the case where all L's are equal?

Well, the fact that it's searchable on the Internet is a good counterargument.

It seems that we can speed up editorial solution a little by using one more bitmask in the dp state, instead of generating all (

N- 1)! permutations..Nice, you are right, we didn't notice that. In fact, 5! < 2

^{5}·5, but the complexity becomesO(2^{2N - 2}·N^{3}·C^{2}).Solution for C?

I solved by using bitset.

O(n^{2}×a) DP is obvious but if I use bitset seems like we can achieveO(n^{2}×a/ 64). Is it true that bitset is always very fast in use of bitwise operation?Something else that passes is probabilistic solution of shuffling array and then assuming that optimal solution likely never has delta at any time exceeding 50000 (that is when we are solving problem of partitioning array into two halves as close in sum as possible, in our dp we can limit current delta between halves to [-50000, 50000]).

The delta between halves is at most 2000 because if it exceeds, we can move one element from the larger side to the smaller side and get a better solution.

So this makes sense for the final delta, however how does this help us during our dp? As in although final delta is <= 2000, the delta at when we are say midway through our dp can be greater, or is there some easy way to avoid this?

Right, I didn't get exactly what you were trying to say. In that case the delta can indeed be larger.

The final delta is indeed at most 2000, but if we add elements to halves in random order, intermediate deltas may be larger. I assume they are bounded by something like with high probability, since the process looks like a random walk.

Can we binary search on the answer (say

X) and see if exactly (2^{N}- 1) / 2 subsequences have sum less thanX? Would that work within TL?We can use DP to check that.

f(i,j) represents no. of subsequences using firstinumbers with sum <j. Maintain only 2 rows in the DP table to avoid exceeding memory limit.Numbers can get very large, on order of 2^2000, what is your plan of avoiding this? Or if you do have such large numbers, I imagine TLE.

Right, I did not consider that. Thanks.

What a coincidence... Getting AC after fraction of a second...

You were 8ms late

Interesting, how did you get this information?

You should ask organizers to accept this. The only thing that matters is submission time.

What makes you to make it required to use bitset in problem C? Is there any trouble if n<500?

We can calculate

Dp[i][j][t] (1 ≤i≤N, 1 ≤j≤N·Max, 1 ≤t≤C) the number of ways to have sumjusing the firstielements moduloP[t] inO(N^{2}·Max·C). We can chooseP[t] (1 ≤t≤C) to be a prime number ~2^{62}. Now we can find for sure the (2^{N - 1})^{th}element if we chooseC= 8 primes.I'm not sure that's the reason though...

Right, we didn't want straightforward counting solutions to get accepted.

And you didn't think about slow languages such as Java or C#? (I know Python is too slow for programming contests though)

We did. Our Java solution using built-in

`java.util.BitSet`

gets accepted in 619 ms, which is less than 1 / 3 of TL.Can you also tell why we'll be able to surely find (2

^{N - 1})^{th}element usingC= 8 primes? That doesn't seem very intuitive to me.Suppose you have that

x≡ 2^{N}(modP_{t}) for everyt(1 ≤t≤C) then by Chinese Reminder Theorem . Because we choose 2^{N}to be smaller than the solution is unique in our case.Why not just use big integers to compute dp?

wrong

How do you do it with fewer primes?

Oh, yeah, you're right, I feel stupid now. It's just the first that came to my mind...

Atcoder is another judge?

It's the contest of another online judge, Atcoder.

Thanks

Also there is another online judge Csacademy

Let the downvotes fall down on me... :(

What could be the worst case for problem D subask.1 ? I try q=1000 with all a=b=1000, and c=1, d=100. and it runs very fast on my computer, but I get TLE on it when submitting it.

It gives verdict on all cases combined.So if you attempt for partial you will get TLE. But the score reflects on standings page.

Where can I find author and testers solutions. It would be great to add the links in editorial itself

AtCoder Race Ranking

In problem E, I don't understand the explanation of the "Programmer's way" to figure out that the number of DP state is not large.

Va mask of bit or a single bit?V_{i}means that characteriis logical AND of the corresponding characters in the original string". In the DP recurrence, different value ofKand |A| will give different set of "corresponding characters". So what exactly is "corresponding characters" here?f({{1}, {2}, ..., {N}}) forN= 100". What does {1}, {2}, ..., {N} here mean?Suppose we are given string

Sas input. Then, we callf(S). LetTbe any string passed as a parameter tofin a later call. It turns out that for everyi, for some sets .Now, instead of accepting

Sas input, accept only its length |S| and assume the general case. Initially, for alli. For subsequent calls off, these sets can be formed in the same way as DP is calculated.Thus:

Vis a bitmask.Kand |A| results in a different call tof.i, or, equivalently, a bitmask with a single set biti.I think I got it. Thanks for the clarification.

Just a curious question... Did you intend that many people would come up with the "Programmer's way" and "Mathematician's way" during the contest, tourist?

Of course I expected most people to come up with "Believer's way", or even just "Submitter's way" :)

I had to prove my solution in order to set this problem, though, and I came up with "Programmer's way", but I didn't expect anyone to implement it. rng_58 came up with "Mathematician's way" while solving the problem, and I think it was possible to convince oneself using similar observations during the contest.