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

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

Спасибо за участие!

1445A - Переупорядочивание массива придумал meshanya, а подготовил ch_egor

1445B - Отборочный этап придумала Андреева Елена Владимировна, а подготовил ismagilov.code

1444A - Деление придумал vintage_Vlad_Makeev, а подготовил grphil

1444B - Разбивай и суммируй придумал и подготовил NiceClock

1444C - Тимбилдинг придумал V--o_o--V, а подготовил wrg0ababd

1444D - Прямоугольная ломаная придумал Zlobober, а подготовил DebNatkh

1444E - Найти вершину придумал V--o_o--V, а подготовил 300iq

Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
  • Проголосовать: нравится
  • +121
  • Проголосовать: не нравится

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

Автокомментарий: текст был обновлен пользователем ch_egor (предыдущая версия, новая версия, сравнить).

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

Fast tutorial!

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

very fast tutorial thanks.

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

Great sets of problems with short statements!

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

Thanks for the quick tutorial!

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

How the heck was this really 14 hours ago? xD

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

I do not understand the sentence: "Any difference |pi−qi| in our sum will be the difference of one element of R and one element of L." Sombody explain the meaning of it?

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

    That means either pi belongs to R and qi belongs to L, or pi belongs to L and qi belongs to R. Since this is true for all pi and qi, then the sum of |pi — qi| is the same as the sum of R — L

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

      The key point is that for any pair pi,qi it is true that one of the if from set L and the other from set R. Unfortunatly the sentence does not say that. Instead it states it as a property of the sum, which is confusing.

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

        can you please elaborate.. I cannot find the connection between L and R being sorted and this logic.

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

          L is per definion the lower half, and R the upper half. They are not sorted, but each element in L is smaller than each element in R.

          Then, if you have any permutation of all elements, cut them in two sets of same size and sort the two halfs/sets according to the statement. ie left one ascending, right one descenting.

          Then it turns out that for all p[i],q[i] the two values are from original L and other from R. That is true independend of any sum, so it is not a property of the sum, but a property of the way the sorting of the halfes is defined.

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

Why does this give WA for (C) Division : https://codeforces.com/contest/1445/submission/97331021 ?

Fails at 7th Test (Passed the Pretests)

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

    In the first WA testcase, the numbers were $$$p=2^4 \times p_1 \times p_2$$$, $$$q=2 \times p_1$$$, where $$$p_1,p_2$$$ are some large primes. Your solution printed $$$2^4 \times p_2$$$, where the correct answer is $$$p_1 \times p_2$$$

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

    Mine WA at 18th T_T Link to solution

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

Как мы можем найти С из N по 2 * N в задаче D для Div2, если нам нужно выполнять операции по модулю, а в формуле деление? Треугольник Паскаля?

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

    Можно делить в модулярной арифметике по простому модулю. Погуглите modInverse, делается расширенным алгоритмом Евклида, например.

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

What does $$$O(n^2 \log n \ldots n^4)$$$ mean, wtf xd?

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

    Well... It is something between $$$n^2 \log n$$$ and $$$n^4$$$ :) It depends on your $$$T(n)$$$.

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

    It means that it is between $$$O(n^2 \log n)$$$ and $$$O(n^4)$$$ depending on your implementation. I agree, unexplained arbitrary notations should be avoided...

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

For Div1 Problem B, I just made random tc for n = 1, 2, 3 and solved on paper. Then I found that cost is always same and got AC xD

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

I misread non-increasing as non-decreasing in problem B and worked almost 2 hours on it(

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

Problem statements were really very straight forward...No time wasted in reading useless story and understanding problem statements

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

Can anyone help with counting $$$С_{2n}^{n}$$$ without overflow?

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

Div2 A, why do we have to check for all i? Like after sorting one array in descending order, shouldn't it be sufficient to check a[0]+b[0] and a[n-1]+b[n-1]? Can someone please give an example where this fail?

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

    Let us consider the following test case

    1
    3 4
    1 3 3
    3 2 1
    

    Here, a is sorted in ascending order. And b is sorted in descending order. also, a[0]+b[0] = 4, which is equal to 4, and a[n-1]+b[n-1] = 4, which is equal to 4.

    However, a[1]+b[1] = 5, which is greater than 4

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

Did someone managed to solve div1B without the observation that any partition holds equal sum?

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

Can anyone please tell me why is my code giving wrong answer on test 18 for problem C- Division.

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

Thanks for update the rating fast!

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

My rating goes bruh 'cause I forgot to reset res = 0 after each testcase when solving C lol

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

Can someone please explain solution of Problem Div2C/Div1A more clearly?

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

    cases

    1) if p%q!=0, then answer is p itself

    2) else we need a largest factor of p such that it is not divisible by q
    let's say the prime factorization of p is 2^x*3^y.. and for q as 2^a*3^b.., as p%q==0 then x>=a, y>=b and so on for every prime factor of p.

    Now is the trick/move, we can find possible x of p by removing some factor of p from prime factorization of p, for eg. if I remove 2^(x-a+1), you can see that p/2^(x-a+1) is no more divisible by q. That's it you have to try removing different prime's power and the one with maximum p/prime^(x-a+1) is the answer.

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

      Your explanation is really very much nice. Loved it and understood it just by reading once. Wanted to thank you and also I have a doubt. Won't the prime factorization takes O(sqrt(p)) time and won't it be of the order 10^9. Isn't the time constraint of 1-second means 10^8 operations?? Or finding the prime factorization of q will be enough??

»
3 года назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится
What's wrong ???
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Have some patience, it will automatically update in some time.

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

    how did you enable dark mode??

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

      There are many extensions on the Chrome web store. I use "Stylish". It has both codeforces and codechef dark modes. Although they are not completely optimised for visibility.

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

Please give a detailed explanation of Div 2 C

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

    I understood one approach. Here it is:
    if $$$p\% q\neq 0$$$ then $$$x=p$$$
    else we can represent $$$p$$$ and $$$q$$$ as follows:
    $$$p={p_1}^{k_1}*{p_2}^{k_2} \dots {p_y}^{k_y}*{p_{y+1}}^{k_{y+1}} \dots {p_m}^{k_m}$$$
    $$$q={p_1}^{l_1}*{p_2}^{l_2} \dots {p_y}^{l_y}$$$ where $$$p_1,p_2 \dots p_m$$$ are prime numbers.
    Here $$$k_1 \geq l_1, k_2 \geq l_2, \dots ,k_y \geq l_y$$$ because $$$p\% q=0$$$
    Now we have to take some factor of $$$p$$$ such that it is not divisible $$$q$$$. We can do this by taking some prime number power equal to one less than corresponding power in prime factorization of $$$q$$$ or you can say that we have to divide $$$p$$$ by that prime factor until $$$p$$$ is not divisible by $$$q$$$ . We can do this for all prime factors of $$$q$$$ and take the maximum one. Here is my submission

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

      Exactly my approach. But here's what happened to my submission

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

      You have done sieve upto 2e5+9 only right, how does it work when q is divisible by a prime number greater than N?

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

        What is N here?

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

          N used in nubir345's code = 2e5+9

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

            see this line:

            if(temp>1){
                v.eb(temp);
            }
            

            You should see that if there is such a prime then there can only one such prime with that of power 1. So after the loops, if temp>1 then it means that temp is a prime. And it is taken into consideration.

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

    I don't know if it will make more sense or not the way I thought is ,

    Let's call the power of a prime number in prime factorization of a number prime count.

    if a number(x) has at least one prime count greater than another number(y) than y%x!=0 Suppose , x=2*2*2*2*3

    and y=2*2*3*3*3*5

    then y/x will be something like (3*3*5)/2 which won't be a integer.

    so now for the given two numbers p & q , we need to find a 'x' that where p%x==0 & x%q!=0and we have to make it the biggest. So we start by making x=p (in another way saying taking all the primes in p) then checking for every prime in q can we make the prime count of q greater than that of x. We print which ever gives the largest number.

    vector<ll>primes;//all the primes in the prime factorization of q.
    for(ll i=0;i<primes.size();i++)
    {
        ll x=p;
    
        while(x%primes[i]==0)
        {
           x/=primes[i];
           if(x%q!=0)
           break;
        }
        
        ans=max(ans,x);
    
    }
    

    so suppose ,

    p=2*2*2*2*3

    q=2*2*2*3

    then x will be =2*2*3

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

I passed Div1 D with $$$O(n^2C/bitset)$$$ using "malaysian knapsack", $$$C$$$ is the sum of length.

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

Div2 D/Div1 B is a beautiful problem, with a wonderful proof, thanks

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

    So sad I was not able to see this during contest. Intuition really plays a big factor in that I think. I straight went to calculating combinations.

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

1444B — Divide and SumF how to think like that ? can some one explain the way of thinking step by step ? Please

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

    Think of it this way-> Lets say the array is sorted, then the problem get reduced to choosing a subsequence of n elements, reverse it and then find the "cost". Now try to find which elements will always contribute a negative value ( that is -a[i]) and which will contribute a positive value (that is + a[i])............you will realise that elements from 1....n always contribute a negative value, while elements n+1.....2n contribute a positive value. In the end just multiply the final answer with the number of possible combinations.

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

In the editorial of Problem C, why q is not divisible by x?

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

proplem b was not clear enough and the proplem must be more than that

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

How can one solve Div2D if p and q are both sorted in non-decreasing order? (spent hours trying to upsolve this variant then saw the editorial and was like f**k me :P )

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

    same here. QAQ

    I came up with a $$$O(N^2)$$$ solution, which I calculated the appearance of each pair $$$(a_i,\ a_{i+1})$$$ (sorted). Wondering if it's possible to reduce it down to $$$O(N)$$$?

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

Problem E appeared at the eleventh POI.

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

Can someone explain , why the solution got WA ? Thanks in Advance!! Problem — Div2A Link to my solution :https://codeforces.com/contest/1445/submission/97363313

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

    You didn't sort

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

    Sorry I didn't see in the problem that the arrays are already sorted.

    The problem is there are multiple cases in ONE test case, and if you are exiting the input with return (in one solve() iteration) once you found something >=x, the other numbers left in a,b array won't be read, therefore all the following inputs are wrong.

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

There should be a special tag for problems like 2D/1B: LOL problem

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

The way I thought about problem DIV2-D : Every element either gets added or subtracted, if we consider individual contribution of elements.
Added : when the corresponding element in other sequence is lesser;
Subtracted: when the corresponding element in other sequence is greater;

Let's now see when an element is subtracted : Consider p, q be the non-decreasing and non-increasing sequences respectively;

=> p[1] <= p[2] <= ....... <= p[n] ------- (1)
=> q[1] >= q[2] >= ....... >= q[n] ------- (2)

Let's say p[i] contributes it's negative, i.e. it gets subtracted, Then we can say from (1) that number of elements greater than or equal to p[i] are n-i; Also since q[i] >= p[i] (as p[i] is being subtracted), all of (q[1], q[2] .... q[i]) >= p[i];
Now we can say that atleast (n-i) + i = n elements are greater or equal to p[i];

Similarly we can derive the condition for the other case !

Which proves that for a value to contributes it's negative it has to be in first half of the sorted array of all values !
Hope it helps, sorry if this approach is mentioned above, I dint read all the comments !

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

There is a spell mistake in solution of 1C.

Para.4, the last word "answer" was mistaken for "asnwer".

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

Fun Fact — sinus_070 was the first person to get an AC on 1B/2D. That's because he created the same problem on topcoder a few months ago. Click 1 Click 2

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

In Div1C, there are lots of submissions AC using DSU to find the number of "bad pairs" instead. Could anyone explain a little bit about this solution? Thanks so much <3.

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

    DSU without path compression can cancel the previous merge. So you can add all the edge between two groups, using DSU to judge whether this group pair is 'bad', then delete the edges and restore the DSU.

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

      I tried to use dsu during the contest.But will "delete the edges and restore the DSU" get TLE?

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

        I think one edge can be added or deleted up to k times.(unless compress the connected component of same color)

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

          An edge which connect two different group would be added and deleted just once. Initially add all edges that the two node which it connect belong same group. Then select two group (ignore pairs which don't appear), add all edges between them, check if this pair valid, and delete these edge.

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

    You may see the technique using DSU with rollback to check bi-graph in this problem 813F - Bipartite Checking.

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

    Wow thanks <3

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

Verdict shows accepted then why my rating decreases?

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

Can somebody please explain me the logic of div 2 C. Please..

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

    I can tell you my logic which got accepted. for q, i calculated it's prime factors and their powers (how many times a particular prime no occured) . i stored this in a vector of pairs and then checked whether p is divisible by all prime factors of q or not. if not then p is the ans. else suppose the power of a prime factor of q in p is p1 and in q it is p2. so, i divided p by pow(pf,p1) and multiplied by pow(pf,p2-1). i did this for every factor of q and calculated the maximum number formed out of them. sol link- https://codeforces.com/contest/1445/submission/97400076

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

      Can you please explain me a little why you are at first removing all the factor of that prime and after that multiplying it by p2-1, What's the intuition behind that?

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

        let q be of the form 2^p1*3^q1... .then q will divide p only if p has atleast power of 2(same implies to other faCTORS) equal to p1 in it . therefore we reduce power of 2 (for example) in p to p1-1 and then the number so formed will not be divisible by q.so we reduce power of such prime factor in p such that it reduces value of p by least amount .

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

Am I the only person who felt Div2-D is easier than Div2-C ?

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

    Div2-D is easy once you see that property that the sum is same for all permutations. If not, then not. Additionally the statement was formulated in a way that it was easy to get it wrong concerning the ordering of the two halfs L and R.

    Div2-C on the other hand is fairly clear, all that division and things. What else can we do than a prime factorization of the only value where we can do it? Once realized that it is not so hard to use the fatorization to construct ans.

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

Can anybody please explain me the editorial of problem A. Div2 ? I am not getting it please!

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

    Consider the smallest value in a[], min(a[]). Which one of b[] values would be "the best" to pair with that?

    Well, in b[] there is a biggest value, max(b[]). If $$$max(b[])+min(a[]) > x$$$, then there is obviously no solution.

    Else it is optimal to "get rid of max(b[])" by using it. Then repeat with the next smallest value in a[]... same again, you will pair it with the then biggest value in b[].

    You end sort a[] ascending, and b[] descending, and checking all pairs a[i]+b[i].

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

About 1444C - Team-Building, can anybody please explain me the sentence "If the path of the cycle in this component ends in the same side where it has started, then it has even length, and odd otherwise."? Thanks in advance.

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

How to solve 1444B - Divide and Sum if $$$f(p,q)$$$ set to be $$$f(p,q) = \sum_{i = 1}^n x_i y_i$$$

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

    Now, I know how to do it in $$$O(n^2 \log n)$$$ time complex and $$$O(n^2)$$$ space complex if $$$f(p, q)$$$ is bilinear.

    Just note that if $$$x_i$$$ belong to the left side, then $$$y_i$$$ belong to the right side, and vice verse.

    So we only have to consider $$$f_k(p, q) = \sum_{i = 1}^k x_i y_i$$$ with $$$x_k$$$ in the left side and $$$y_k$$$ in the right side.

    And the answer with be $$$\displaystyle 2 \sum_{p, q} \sum_{k = 1}^ n f_k(p,q)$$$

    In order to compute $$$\displaystyle \sum_{p, q} f_k(p, q)$$$, we only have to computer sum of $$$k$$$-subarry of left and right side. donated by $$$(l_1, \cdots, l_k)$$$ and $$$(r_1, \cdots, r_k)$$$, and then $$$\displaystyle \sum_{p, q} f_k(p, q) = \sum_{i = 1}^k l_i \cdot r_i$$$.

    the origin time complex is $$$O(n^3)$$$, but there is a convolution in above computation, so we can solve this problem with time complex $$$O(n^2 \log n)$$$ with the help of NFT.

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

Please help, I want to know where and why O(r) code for nCr mod p fails!!!

long long nCr(int n, int r){
    if(r>n){
        return 0;
    }
    int i= 0;
    int t =r;
    long long ans = 1;
    while(t--){
        ans = ( (ans*(n-i))/(i+1) ); // ans is always less than p, so it won't overflow, right??
        ans = ans%p;  
        i++;
    }
    return ans%p; 
}
»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

how solve problem D if it is given that both sequence should be non-decreasing order or non-increasing order?

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

how to solve problem D if it was given that both p & q should be non-increasing order or non-decreasing order?

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

    sort the origin array $$$a$$$ and then the answer for both case is

    $$$ \displaystyle 2 \sum_{k = 1}^n \sum_{j = 2k}^{n + k} \binom{j - 1}{k - 1} \binom{2n - j}{n - k} a_j \quad - \quad 2 \sum_{k = 1}^n \sum_{i = k}^{2k - 1} \binom{i - 1}{k - 1} \binom{2n - i}{n - k} a_i $$$

    time complex $$$O(n^2)$$$

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

.

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

Can someone please explain why my div1-b solution is failing on test case — 8. Div1-B Solution

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

The answer for the test case (P=557307185726829409 && Q= 746530097)according to the judge is X=1 why cant we have X=674968226.