It's optimal to do the biggest possible step everytime. So elephant should do several steps by distance 5 and one or zero step by smaller distance. Answer equals to
Solution 15550796
We are given array which contains only ones and zeroes. We must divide it on parts with only one 1.
Tricky case: when array contains only zeroes answer equals to 0.
In general. Between two adjacent ones we must have only one separation. So, answer equals to product of values posi - posi - 1 where posi is position of i-th one.
Bonus: what's the maximal possible answer for n < 100?
Solution 15550806
First radius equals to zero or distance from first fountain to some flower. Let's iterate over this numbers. Second radius equals to maximal distance from second fountain to flower which doesn't belong to circle with first radius. Now we should choose variant with minimal r12 + r22.
Bonus: It's O(n2) solution. Can you solve problem in O(nlogn)?
Solution O(n2) 15550812
Solution O(nlogn) 15550822
Answer equals to one if all coordinates x or y of points are same.
When answer equals to two? Let's iterate over all pairs of points. Let first point in pair is beginning of polyline, second point is end. Only one or two such polylines with answer two exist. If third point is on the polyline it belongs to rectangle with corners in first two points. We can just check it.
Else answer equals to three. We can build vertical lines which contains the most left and the most right point and horizontal line through third point. If we erase some excess rays we will get polyline.
Solution 15550843
617E - XOR and Favorite Number
We have array a.
Let's calculate array pref (pref[0] = 0, ).
Xor of subarray a[l...r] equals to .
So query (l, r) is counting number of pairs i, j (l - 1 ≤ i < j ≤ r) .
Let we know answer for query (l, r) and know for all v cnt[v] — count of v in a[l - 1...r]. We can update in O(1) answer and cnt if we move left or right border of query on 1. So we can solve problem offline in with sqrt-decomposion (Mo's algorithm).
Solution 15550846