Комментарии
Solution for F

Actually it can be done in by using two pointers technique.

+6

That's probably caused by the constant factors. I think the main reason is that for the computer for (j = i * i; j <= N; j += i) a[j] = false; loop is more predictable than the loop of O(n) sieve.

But yeah, the O(n) sieve has some advantages for multiplicative functions, especially if they're more complex ones.

+13

Yes, it is possible. This blog post explains how and why it can be done.

На cyand1317Codeforces Round #487 (Div. 2), 8 лет назад
+4

You're probably looking for problems about constructive algorithms then. Codeforces has many problems about them here. Not all of them are very similar to C, but some of them are.

На cyand1317Codeforces Round #487 (Div. 2), 8 лет назад
0

I made a 50x50 grid, so that upper left 25x25 is filled with A's, upper right with B's and so on. After that you can put the remaining components to the grid by replacing some 1x1 areas with them.

Here are my solutions for A and B, I hope they can be understood even though they're not very formally written.

Solution for A
Solution for B
80p solution for C

It can be done with a binary search. We try to binary search the highest upper bound of passengers x such that there are no solutions. If there is a solution, then you want to keep the number of passengers as close to the upper bound x as possible without exceeding it. You'll also need to ensure that after leaving a station the number of remaining passengers r is greater than or equal to the number of passengers currently in train, so you'll need to update the upper bound x to min(x, r).