Блог пользователя okwedook

Автор okwedook, 3 года назад, перевод, По-русски

Все задачи названы в честь песен моей любимой группы Hippie Sabotage. Рекомендую их послушать!

1826A - Trust Nobody

Подсказка1
Подсказка2
Решение

C++ реализация: 204718333

1826B - Lunatic Never Content

Подсказка1
Подсказка2
Решение

C++ реализация: 204718497

1826C - Dreaming of Freedom

Подсказка1
Подсказка2
Подсказка3
Решение

C++ реализация: 204718535

1826D - Running Miles

Подсказка1
Подсказка2
Решение

C++ реализация: 204718553

1826E - Walk the Runway

Подсказка1
Подсказка2
Подсказка3
Решение

C++ реализация: 204718603

1826F - Fading into Fog

Подсказка1
Подсказка2
Подсказка3
Решение

C++ реализация: 204718641

Разбор задач Codeforces Round 870 (Div. 2)
  • Проголосовать: нравится
  • +165
  • Проголосовать: не нравится

»
3 года назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

instant editorial

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

What? Hints are in Russian and solutions are in English.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

I'll add implementations as soon as system testing finishes.

Thanks for participation, I hope you liked the contest even though problem A was kinda hard.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +68 Проголосовать: не нравится

In Problem F, was the inaccuracy 1e-4 in projection set deliberately? Maybe the projection point is fairly accurate, but the judge adds a random number smaller than 1e-4. Otherwise It's simple to find all points by y=0, y=-0.001x (2 queries).

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I wrote a strange solutino for E and not sure if it will FST.

I notice that the bottleneck is calculating the relationship of (i, j), it's O(m) originally. The whole algorithm is O(n^2m). So I add two optimization strategies:

  • When the transition can be from F[i] to F[j], I ommit the nodes of the solution chain of F[i]. This may be hack by this array:

1 2 3 4 5

1 2 3 4 5

...

1 2 3 4 5

1 1 1 1 1

  • So I add another strategy: If [line x] causes j to be unable to connect to i. The next link judgement will start from [line x].

https://mirror.codeforces.com/contest/1826/submission/204635663

»
3 года назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

shit as predickted

»
3 года назад, скрыть # |
 
Проголосовать: нравится -58 Проголосовать: не нравится

Worst div.2 that I've ever participated in.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Is D can be solved using ternary search ?

Isnt it f(len) = max1+max2+max3+len for all length a convex function

I tried during contest but couldnt do. Can somebody let me know whether i am correct or not

»
3 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Problem B is from past contests.

Problem Link: https://mirror.codeforces.com/gym/102035/problem/I

»
3 года назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

In $$$B$$$, it should be "which basically says $$$x$$$ divides $$$a_i−a_{n−i+1}$$$"

»
3 года назад, скрыть # |
 
Проголосовать: нравится +29 Проголосовать: не нравится

You can solve problem 1826E - Walk the Runway in $$$O\left(n^2 \times m\right)$$$ in C++ without bitsets. Based on naive $$$O\left(n^2 \times m\right)$$$ approach, you need to apply next optimizations one-by-one for getting 1872 ms.

Optimization 1
Optimization 2
Optimization 3
Optimization 4

Accepted 1872 ms submission

  • »
    »
    3 года назад, скрыть # ^ |
    Rev. 3  
    Проголосовать: нравится +19 Проголосовать: не нравится

    Optimization 1 is redundant, this part of solution takes less then 100 ms.

    __restrict keyword is also unnecessary, your code doesn't change arrays.

    I tried to use similar approach but didn't came up with genius optimization 2.

    I changed your check function a little bit, now solution is 1263 ms :)

    204651252

    • »
      »
      »
      3 года назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Thank you, idea with unsigned difference instead of comparison is very cool too.

      I think 1263 ms is not so fair, because during system testing a lot of solutions are running simultaneously on same cpu with common L3 cache (L2 and L1 are isolated and are private for each core) and more likely that someone will push out your data from L3 cache, then it will be pushed out of L2, then will be pushed out of L1, because it is required for data to be in cache of higher level. But I can be wrong.

      I remember that runtime of my original solution was 1200 ms in the custom invocation during a contest with m = 5000, n = 500 and each row is sorted permutation, but it became 1700 ms after submit (pretests) and 1872 ms during system testing.

      • »
        »
        »
        »
        3 года назад, скрыть # ^ |
        Rev. 4  
        Проголосовать: нравится 0 Проголосовать: не нравится

        I tried to submit both versions within a second (obviously not during contest). I even tried to return back "restrict" keyword in my version. I repeated it 3 times. Here are results. Rather unstable but highest bit trick tends to be faster.

        Screenshot

        I think cache is not a bottleneck here. The main optimization is SIMD usage. uint16_t helps to do more operations per vector instruction.

        Why highest bit trick is faster? Well, I guess sometimes bool type behaves in other manner. Like a widely known fact that construction "if (a && b)" for many compilers is actually "if (a) if (b)". I remember in some video a guy explained if you want your SIMD to work properly use bool very carefully :)

        About 1200 ms on sorted max test — maybe branch predictor memorized this simple pattern and helped to reduce time in some way (I'm not sure, just an assumption).

»
3 года назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

I think my solution for D is different, and slightly over-complicated comparing the editorial.

I thought of the array being empty first and then I put the elements from higher to lower beauty in their position, at each iteration, the answer is to choose the best three consecutive sights, they are consecutive because the answer has the three most beautiful sights in some [l, r], when the minimum of them is put in the array, they are consecutive because there is nothing between them. Finally adding one sight to the array creates only three new trios of new possible consecutive sights, (e. g. m is the index of the new sight [a, b, m, c, d], the new three consecutive trios are [a, b, m], [b, m, c] and [m, c, d]), so I represented the dynamic array with sets, and check the three new possible trios after I put an element in the array.

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I think you could have implemented it easier if you would have maintained 2 arrays of neighbours (l[i] = left neighbour of i, r[i] = right neighbour of i). Initialise the arrays with the 3 biggest numbers. When you have to add a number x on position i you use the positions of the closest to left (lPos) and the closest to right (rPos) elements greater than or equal to x (that are visited already) and update l and r arrays accordingly ( l[i] = lPos l[lPos] = i etc.). Next you take 2 elements from the left and 2 from the right using these arrays and do the answer updates. There are some edge cases on the margins but can be easily handled by adding dummy numbers.

    As a side note, I like your idea:)

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится -10 Проголосовать: не нравится
so the total time complexity would be O(n2m/64)
, which is fast enough.

So why my solution of E 204620376 got TLE?

Update: Now I optimized it in 204648297

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

To my mind, if there was problem E instead of problem D (but with smaller constants,like m<=100, n<=1000), this contest would be much better. Cause D is too easy for this position, and E is quite easy too (comparing to other "E" problems)

»
3 года назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

Why is this submission getting Idleness Limit Exceeded on Test 120?

EDIT: replacing 0.0002 with 0.0002004 gives AC :(

»
3 года назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

You can solve problem D even if instead of finding 3 best elements we had to find k best elements in time complexity of O(k*nlogn). For finding best two, you can do the following : For all i, first insert a[i]-i in the set. Now iterate on i from left to right, erase a[i]-i from set and find maximum value in set(mx) and set b[i] = a[i]+mx+i. b[i] now contains the answer for maximum 2 values. Now you repeat this by inserting b[i]-i and setting as c[i] = a[i]+mx+i again. Repeating this allows to pick k best elements in O(k*nlogn)

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится +14 Проголосовать: не нравится

    Nice variant!

    I think this can be optimized into O(NK) time: define $$$s(j, l) = max (A[i_1] - i_1 + A[i_2] + A[i_3] + ... + A[i_l])$$$ for any $$$i_1 \lt i_2 \lt ... \lt i_l \lt j$$$ (that is: the maximum value of a subsequence of length $$$l$$$ using elements before $$$j$$$ and baking in the $$$+ l$$$ term). Then the answer is $$$max(s(j, K-1) + A_j - j)$$$ over all possible values of $$$j$$$ ($$$1 \lt j \lt N$$$).

    We can go through the array from left to right and calculate $$$s(j, l) = max(s(j - 1, l), s(j - 1, l - 1) + A_j$$$ in O(K-1) time, for an $$$O(NK)$$$ time and $$$O(K)$$$ space solution.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

What is the fairly straightforward solution using DP for D mentioned in the editorial?

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится +19 Проголосовать: не нравится

    DP method uses the same idea: two of the three biggest values are in left and right boundary. Otherwise we will shorten the range and get smaller cost.

    f[i][j] is the answer of choosing j numbers in first i of n numbers. 0<=j<=3.

    the cost -(R-L)=L-R can be added into calculation in running process.

    When the first number is selected, left boundary L is fixed to its index. This is f[i][0]->f[i][1], add index i(=L) to answer additionally.

    When the third number is selected, right boundary R is fixed to its index. This is f[i][2]->f[i][3], subtract index i(=R) to answer additionally.

    The method can be expanded to selecting k numbers rather than 3 numbers, with time O(nk).

»
3 года назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

Thank you for preparing for this round, despite the A problem is hard than B,C hh:)

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится
»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In problem C,

First we need to notice, that in order to keep some amount of options indefinetely, this number has to be at least 2 and divide n.

How to prove that number d divide n ?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

I have a different solution for D. I solved it using the divide and conquer method. I must select three elements that maximize the answer from 1 to n. At first, I divided the range into two equal segments 1 to n/2 and n/2+1 to n. Now, there are four cases. 1. All three elements are on the right side. In this case, we have to solve it for the range n/2+1 to n. 2. All three elements are on the left side. In this case, we have to solve it for the range 1 to n/2. 3. Two elements are in the left segment and another one is in the right segment. 4. Two elements are in the right segment and another one is in the left segment. I have to take the maximum of these four results. For case 3 one element is on the right side. I have iterated over the right segment for the element. If I take ith element it will make profit li and to take this element I have to travel i-n/2 miles. So, the ultimate profit is li-(i-n/2). I took the element which makes the maximum profit. For the left segment, there are two elements. I have iterated over the left segment. If the ith element is the first element of the two elements then I have to travel n/2-i miles. I will take the maximum two elements x and y from the i to n/2 range. Then it will make a profit of x+y-(n/2-i). I have chosen that make maximum profit. Case 4 is similar to Case 3. The complexity is O(nlogn). Here is my solution. https://mirror.codeforces.com/contest/1826/submission/204653388

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

19k registrations and only 5k participants nice A ;)

»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Problem D can be solved easily without precalculating anything. In fact, it can be solved in O(1) space and O(N) time: https://www.codeforces.com/contest/1826/submission/204656798

The logic is similar to the editorial. We rewrite the problem as: maximize $$$(A_i + i) + A_j + (A_k - k)$$$ subject to $$$i \lt j \lt k$$$. Then we can run the values $$$k$$$ from 1 through N, and keep track of the maximum values of $$$A[i] + i$$$ and the maximum value of $$$(A_i + i) + A_j$$$ (see the code for details) at each position.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +59 Проголосовать: не нравится

Problem E has weak tests because some AC submissions used random or checked if 50-100 comparisons were ok, while there are 500 needed.

I've added one test to hack these submissions but its still not ok, i guess.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

okwedook I still don't understand why 2 queries aren't enough in F. Is it not ok to get the x coordinates through projection on y = 0 and y coordinates through projection on x = 0? It is also written that ans should be correct till 3 decimal places and since the noise is < 10−4 for each point through the query, shouldn't we be good?

  • »
    »
    3 года назад, скрыть # ^ |
    Rev. 5  
    Проголосовать: нравится +8 Проголосовать: не нравится

    From the statement:

    In one query, you can ask some line ax+by+c=0 and get the projections of all n points to this line in some order

    The points are not nescessarily returned in the same order every time. Thus, the two following cases are indistinguishable from each other with just queries $$$x = 0$$$ and $$$y = 0$$$:

    For both of these cases you could recieve the following answers:

    $$$x = 0 \ \Rightarrow \ 0\ 1\ 0\ 2$$$

    $$$y = 0 \ \Rightarrow \ 1\ 0\ 2\ 0$$$

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Am I the only one not getting the solution of A? :(

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    This much is obvious that the number of liars can range anywhere between [0, n] inclusive. Say the no. of liars is L.

    From the statement: Some of them might be liars, who always tell lies. The i-th person says "There are at least L liars amongst us".

    Since liars always tell lies, they will surely say that the no. of liars are atleast L+1. So these people will always report a value >= L+1

    So, if for some value of liars = L, if you are able to find exactly L people who say liars are > L then that means that L is actually the correct no. of liars.

    You can iterate over all all possible values of L and check.

    AC submission: 204649911

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Which part don't you understand?

    Assume the number of liars is $$$x$$$. Then all people who said that the number of liars was greater than $$$x$$$ were lying! So to count how many liars there actually are, you need to count the number of $$$A[i] \gt x$$$ (note that $$$A[i] = y$$$ means the i-th person claims there are at least $$$y$$$ liars).

    It's easy to turn this into an $$$O(N^2)$$$ solution. The challenge is then to optimize this into an $$$O(N log N)$$$ solution.

    • »
      »
      »
      3 года назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Still not getting the logic. Why do we need to count A[i] > x?

      • »
        »
        »
        »
        3 года назад, скрыть # ^ |
        Rev. 3  
        Проголосовать: нравится 0 Проголосовать: не нравится

        People can only speak a falsehood by overestimating the number of liars, not by underestimating, since each person only makes a claim about the minimum number of liars there are.

        Let's look at a concrete example:

        • Anna says: at least 1 person lied!
        • Bernd says: at least 3 people lied!
        • Charity says: at least 0 people lied!

        Then there are four possibilities:

        • Maybe 0 people lied. But that cannot be true, because if 0 people lied, then Charity was speaking the truth, but Anna and Bernd were both lying about the number of liars, so there are 2 liars, not 0.

        • Maybe 1 person lied. In that case, Anna and Charity are speaking the truth, and Bernd is the sole liar, which is consistent.

        • Maybe 2 people lied. But that cannot be true, because in that case, Charity and Anna are speaking the truth, and Bernd is lying, so there is only 1 liar, not 2.

        • Maybe 3 people lied. But that cannot be true, because in that case, all three people are speaking the truth, so there 0 liars, not 3.

        So the only valid choice in this case is $$$x=1$$$.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Petition: set at least 2.5-3 seconds time limit when the intended solution requires >1e8 operations. :)))

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For A, in the case that everyone says that nobody lied, then everyone may have lied, but that is not an accepted answer.

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится +6 Проголосовать: не нравится

    The people cannot say that nobody lied. They would be saying "at least 0 people lied" which is obivously always true (it's impossible for less than 0 people to lie). Thus if everyone says this, everyone must speak the truth and the number of liars must be 0.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone give submission link for recursive dp solution of problem D?

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

I had a somewhat different solution for Problem B, which I'm not sure whether it was intended to pass or not.

Like the official solution, I consider the pairs of numbers that must be made equal (first and last element of A, second and second-to-last element of A, etc.), ignoring the numbers that are already equal (if all are equal, the answer is 0). For the first pair {a, b}, calculate all possible divisors of $$$a - b$$$. Then for each other pair {c, d}, filter down the possible divisors by checking if each divisor is also a divisor of $$$c - d$$$. (submission source code).

This solution is $$$O(sqrt(10^9) + N×k)$$$ where $$$k$$$ is the maximum number of divisors of a number below 10^9 which is around 1000, for an overall ~100,000,000 iterations.

»
3 года назад, скрыть # |
 
Проголосовать: нравится -12 Проголосовать: не нравится

bad contest

problems were not clear or understandable

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Task E is cool, thanks!

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

May I know if it's possible to do problem A faster than brute force and how to do so?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

E can be solved in O(nmlogn). we can build a binary index tree for every city.First, we sort all the models by their beauty in every cities(the first city has the largets weight the second has the second largets ...). then, we can do dp with this order( any reverse in this order is invalid!). When dp, for a model i,we can query every binary index tree for every city to get their previous max dp. for those maximum dp values we choose the minimum one for that one is the valid one.(unfortunately I fst cuz I for got that std::sort is weak sortings qwq)my code

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What a WAnderful contest, I gained so much~

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What is wrong in this this method for C

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

for problem F, the output format of my code is correct in my computer, but I get a WA because "wrong output format Unexpected end of file — double expected". what's up?

204643420

»
3 года назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

If I try to see the implementation it says: You are not allowed to view the requested page. What should I do?

»
3 года назад, скрыть # |
Rev. 3  
Проголосовать: нравится +3 Проголосовать: не нравится

Unable to open C++ implementation

"You are not allowed to view the requested page"

»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

I was not able to solve B. Now my rating is a palindrome too xD

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can D be done without dp??

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What is the distinction between a lie and a contradiction?

6
3 3 3 5 5 6

The above test case gives 3 as answer even though what the 4th element is saying is never possible.

In the same sense:

9
0 1 1 2 2 4 7 8 9

The last 2 says there are atleast 2 liars, and he's right, there are 4 liars, because what the first 4 is saying can never happen. But here the answer is -1. Can somebody explain? TIA

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    In your second example statements of the first 5 people stay consistent with the previous statements, but the 6th person, who is saying that at least 4 people are lying contradicts himself and the rest of the statements, he can't either be lying or telling the truth.

    If the first 5 people are telling the truth then it means that there should be at least 2 and at most 4 liars in the group. Then if the 6th person is telling the truth that actually means that he should be one of the 4 people lying (a contradiction). If he is lying that means that there should be less than 4 total people lying in the group, therefore out of the last 3 people in the group at least 1 should be telling the truth (in turn meaning that there is at least 7 people lying or more, a contradiction).

    Hope this helps!

»
3 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Не даёт посмотреть решение. Недостаточно прав для просмотра запрошенной страницы

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

why still I can't see the authors implementation?

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

My nlogn solution for A with a map: 204718789.

For the life of me couldn't figure out the brute force approach for A (although by looking at constraints it was obvious to me that n^2 should pass).

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Where does the number 64 come from in time complexity of Problem E. O(n^2m/64)

»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

I am facing a weird behavior in problem F. I will query the 3rd line if the minimum distance between any projection of candidate points is at least EPS. When I set EPS = 1E-6 I get TLE, while EPS = 5E-4 will get AC in 200ms. However this is weird since smaller EPS means it is more likely to achieve the condition.

EPS = 1E-6 (TLE): 204744948

EPS = 5E-4 (AC): 204744799

»
3 года назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

How to solve problem D with the DP method

»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

I started solving problem A as soon as the contest started. Gave up after an hour. Had dinner. Started again, thought of a binary search solution; didn't work, then i thought of a linear search solution(the correct one); couldn't implement it, i was just off by one line of code. Gave up. After the contest was over and i looked at the answer it was the hardest facepalm moment of my life.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Coding style is appreciable !!

»
3 года назад, скрыть # |
Rev. 7  
Проголосовать: нравится 0 Проголосовать: не нравится

My thoughts on problem F. Please correct me if you find any issues.

Theoretically, if we choose the degree of slope of our line uniformly in range $$$(0, \pi)$$$, the probability that two points fall on the same line should be 0, and choosing some random fixed slope should also work. However, there are about 200 tests. Consider if each one has $$$t=50$$$ cases, and each case has $$$n=10$$$ points, then the total number of vectors that can be formed is $$$200*50*10^4=10^8$$$. Denote our line as $$$w'x = b$$$, then the maximum of minimum angle between any vector and $$$w$$$ is $$$\frac{1}{2}\frac{ \pi}{10^8}$$$, and the smallest distance between projections of two points is $$$\sqrt{2} sin(0.5\frac{\pi}{10^8}) = 2e-8$$$. Now, this might still be distinguishable by double precision, but the problem can add a $$$1e-4$$$ noise to coordinates. If that noise is added in the direction parallel to our line (that is, orthogonal to $$$w$$$), then it is very easy to swap position of two projected points. Similarly, even if we randomize the slope each time, it is still unlikely to avoid all the vectors (I tried).

However, by the same analysis, if for each test case we choose the maximum possible minimum angle, then the smallest distance becomes $$$\sqrt{2} sin(0.5 \frac{\pi}{25^4 / 2}) = 1e-5$$$. Note that this is still smaller than $$$1e-4$$$. My first guess is that, since the $$$O(n^4)$$$ vectors are formed by choosing pairwise among $$$n^2$$$ points, it actually does not have enough freedom to uniformly spread among $$$(0, 2\pi)$$$, so the true gap is much larger than $$$2e-5$$$. This could be true, but the real reason is that, because all coordinates are in the range $$$(-100, 100)$$$, it is actually impossible for any vector angle to fall in range of, e.g. $$$(0, arctan(\frac{1}{200}))$$$, which is $$$2e-3$$$! This makes the problem completely trivial, as we can actually choose some fixed slope, e.g. $$$a=400, b=1$$$ should be the safest as it maximize the minimum gap. However, if this bound of $$$100$$$ is changed to $$$10000$$$, then we should still use the method by the editorial.

The $$$1e-3$$$ constraint does not matter as we can obtain coordinates from first two queries at the precision of $$$1e-4$$$.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can you please provide the dp approach for problem D. I understood the direct approach, I would really appreciate the help and thanks a lot for the effort.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Problem D , DP solution please explain!

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

why solution of O(m) getting TLE for problem C

bool f(ll n, ll m){ if (n == 1) return true; if (m >= n) return false; while (m > 1){ if (n % m == 0) return false; m--; } return true; }

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why does this approach doesn't work? This solution is more nature for me than GCD one. It's not the TLE, but the answer isn't correct and I can't see failure testcase. Thanks for future replying!

n = int(input()) d = list(map(int, input().split())) mx_mod = max(d) if mx_mod == 0: print(0) continue flag = True for i in range(n // 2): if d[i] != d[-i — 1]: flag = False while d[i] % mx_mod != d[-i — 1] % mx_mod: mx_mod -= 1 if flag: mx_mod = 0 print(mx_mod)

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Your code fails on

    Input:
    1
    5
    1 1 1 3 4
    
    Correct Output:
    1
    
    Your Output:
    2
    
    

    Array $$$[1, 1, 1, 3, 4]$$$ becomes $$$[1, 1, 1, 1, 0]$$$ when calculating all values $$$\bmod 2$$$, which is clearly not a palindrome.

»
3 года назад, скрыть # |
Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

Problem $$$E$$$ can also be cheesed.

The crux of the problem is to efficiently determine if model $$$i$$$ can go before model $$$j$$$. To do this, we know that:

(1) If $$$sum[i] + n \gt sum[j]$$$, then we know that model $$$i$$$ cannot come before $$$j$$$.

(2) If $$$mx[i] \ge mx[j]$$$, then model $$$i$$$ cannot come before $$$j$$$, where $$$mx[i]$$$ is the max rating of the $$$i$$$th model. Likewise, if $$$mn[i] \ge mn[j]$$$, then model $$$i$$$ cannot come before $$$j$$$.

Only if the above $$$3$$$ conditions are not met do we naively check the ratings in $$$O(m)$$$ time.

Once we check these constraints, we know that model $$$i$$$ must go before model $$$j$$$. But we also know that all models that come before model $$$j$$$ must also come before model $$$i$$$, so we add those to the graph.

Apparently, this approach passes. 211357168

Would be interested if someone could hack me...

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For Problem D, I tried using a two-pointer approach, basically moving l or r depending on which value is smaller. Now instead of repeatedly computing maximum in [l,r] , I maintained 3 variables m1,m2,m3 and adjusted accordingly. Here is my implementation.

It is failing on tc 4, can someone help me figuring the error please ?

»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Hello guys i know it's been a while for this div but i have an idea on D that got me ACC so we can make it using seg tree because b1+b3+b2-(r-l) to be maximized we can see it like this : (b1+l)+b2+(b3-r) and for every element from 2 to n-1 we can get max element which is (bj+j) and j from 1 to i-1 and max (bc-c) where c from i+1 to n so result will be max(bi+max(bj+j)+max(bc-c)) and we can query using the seg tree to see the two element we are looking for because both B1 and B3 needs to be the left and right itself