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

Автор Ormlis, история, 5 недель назад, По-русски

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

2024A - Выгодный процент придумала и подготовила Андреева Елена Владимировна при участии Artyom123

2024B - Покупка лимонада придумал Endagorion, а подготовил sevlll777

2023A - Склеивание массивов придумал и подготовил Mangooste

2023B - Пропуск придумал и подготовил adepteXiao

2023C - Ч+К+С придумал и подготовил yunetive29

2023D - Много игр придумал и подготовил Tikhon228

2023E - Древо жизни придумал isaf27, решил и подготовил Ormlis

2023F - Холмы и ямы придумал и подготовил glebustim при участии vaaven

Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Разбор задач Codeforces Round 980 (Div. 1)
Разбор задач Codeforces Round 980 (Div. 2)
  • Проголосовать: нравится
  • +153
  • Проголосовать: не нравится

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

Ormlis when will hidden test case and source code of others be visible?

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

Hi, I cannot prove my solution for div1D nor hack it I hope someone can hack or prove it.

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

i swear i can't figure out for the life of me why my solution to B isn't correct, and i'm not allowed to look at the failing test case either.

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

    I dont know about the formulas, but you should use long long instead of int.

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

      thanks a lot, this was one of the two errors in my code, i just put * 1LL into the formula and it stopped overflowing. i never realized that the whole point of my formula was to keep running till we exceed k, and if k was 1e9 then it would overflow.

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

    Bro your code won't return any output if k is equal to sum of all elements of the array.

    Try

    1

    3 6

    1 2 3

    Comment if you want me to fix it

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

      that wasn't actually the error, i ran this test case before submitting. the actual error was me decrementing n within the loop while having the loop run n times, so if n was 4, it became 2 after the loop ran twice and exited. apart from this i needed to use long long too.

      thanks nonetheless! lesson learnt: always dry run code in a verbose manner :)

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

    Same, I'm new to Codeforces and have been giving contests, but the solution to be just wouldn't come to my mind, I wasn't able to understand the 2nd last test case at all.

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

nvm

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

then $$$c_p \cdot q^{c_p} > (c_p - 1) \cdot q^{c_p - 1}$$$; otherwise, the smallest element can definitely be removed.

why?

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

    I also want to know "why?" Otherwise it's not a proof.

    My way of deriving same claim
  • »
    »
    4 недели назад, # ^ |
      Проголосовать: нравится +32 Проголосовать: не нравится

    I did a similar claim, proves pretty much the same thing.

    Suppose we took an optimal subset whose weights sum up to $$$S$$$, and let's fix some $$$(p, w)$$$ taken ($$$p<1$$$). Then optimality implies that the solution without this element, is not better. We can ignore the product of probabilities on both sides of the inequality and get:

    $$$S - w \leq pS \to S \leq \frac{w}{1-p}$$$. If we took $$$k$$$ elements of probability $$$p$$$, with differing weights, then denote by $$$w$$$ their minimal weight. So $$$S \geq kw$$$, and $$$w$$$ can be plugged in the inequality above to get $$$k \leq \frac{1}{1-p}$$$.

    The intuition behind the whole idea was easier for me to see in contest when I tried to bound the number of elements taken for $$$p = 0.5$$$, and certainly you won't take an element if it doesn't double your current sum.

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

C is a piece of dogShit,i mean why it had to be based on some crap observation.It could have been improved by giving a formal proof of why does that always work. Disappointed...

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

    What's wrong with the proof provided?

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

    Another solution is to sort the arrays by comparing pairs $$$(min(a_{i,1}, a_{i,2}), max(a_{i,1},a_{i,2}))$$$. We can observe that if we move the array with minimal element to the left (and among these with the least maximum), the number of inversions cannot increase, so that's optimal order

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

      lol yeah that was my method

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

      I did the same but received WA: 286985983. I reverted the order of checking (first max and then min as opposed to first min and then max) and it got AC : 287000832. Still unable to understand why that happened.

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

        A grave mistake in my first submission. I modeled <= comparison in the custom comparator of sort function instead of <. Basically, at the end of the custom comparator, I should have returned false instead of true. Correct submission: 287210506

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

        It has more to do with your lambda and how the sorting is handled using std::sort. I don't know exactly why but I think I read somewhere that it is usually recommended to do a "stable sort" with std::sort, as such I simply changed the "true" to "false" when the arrays are same, which makes it a stable sort, and thus got AC, 287213481.

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

      can you check my solution for div2 C . why it is giving me wrong answer 286973745 plz check it.

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

    I solved this problem by just randomly trying different methods of sorting the arrays..
    sort ascending by first then by second
    or vice versa
    or by min in pair .. etc
    and then one of them by luck was successful

    I didn't like the problem because I couldn't reason about it in any way but this shows that one can learn sth from this problem, like what is an exchange argument

  • »
    »
    7 дней назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    Informal proof why sorting by sum works
»
5 недель назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

did someone solve div2B with a multiset ?

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

Ormlis In D2C, how can we solve the problem for arrays of sizes three or more? I tried to solve it by comparing inversions of ab and ba for sorting but it seems this condition is not transitive and thus doesn't work for arrays of twos either, so I had to use some other min/max technique, which doesn't seem to generalise for sizes more than 2.

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

    It will be quite more difficult because we can't use exchange argument anymore

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

    For lists of size four or more, this problem is known to be NP-complete, as you can read in, for example, "A Note on the Complexity of One-Sided Crossing Minimization of Trees" by Alexander Dobler. For lists of size 3, this problem is conjectured but not proven to be NP-complete.

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

got IGM but still cannot solve A during contest, isn't weird?

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

    A simpler solution for 1E:

    When you choose a node as the root node, our answer is at least $$$\sum_{i=1}^n \frac12 s_i(s_i-1)$$$, where $$$s_i$$$ is the number of children of node $$$i$$$.

    However, such a construction may not be able to satisfy some edges that pass through both the son and father at the same time. Let's consider the contribution of this situation to increasing the answer.

    We set a dp state $$$f_i$$$ to represent the number of residual paths that can be uploaded through the parent when the node $$$i$$$ calculates the necessary contribution internally (i.e., the above equation).

    Transfer as follows:

    $$$f_u = \sum_{v\in son_u} \max(1 - [u\text{ is root}], f_v - (s_u - 1))$$$

    After calculating $$$f_ {root}$$$, we must pair the extra paths pairwise, and when we choose the node with the highest degree as the root, we can prove that there must be a match to make the scheme valid:

    [tbd, prove is hard]

    So we can calculate $$$f_ {root}$$$ and add $$$\lceil\frac{f_{root}}2\rceil$$$ to the equation at the beginning.

    using translator.

    287001804

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

Is there a reason the submissions and testcases are still locked?

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

    Just a FYI the source code was visible for few mins I think after the contest ended. I'm not sure was it intended or was it some kind of bug.

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

Samples on D1C are useless

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

B : can anyone tell me what is wrong with my solution , I can't figure it out, frustrated !

I used the same logic

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

I thouth Convex Hull Trick would work on 1D because they seems simular. But it didn't so I'm sad.

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

Here's my binary search approach for Div2 B:

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

I didn't understand D1C from the tutorial, can someone explain it in more detail

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

    A bit late, but here. Consider a cycle of length k in one of the two graphs. Enumerate the vertices along the cycle as the official solution does. So the first vertex gets label 0, second 1, and so on to k-1 which is connected to label 0. Imagine that the cycle branches at the node labeled 5.

    Because the graph is strongly connected if that edge is incident to vertex "e" then there must be a path from e to the node labeled 6 that does not use any edge more than once.

    (why? we have used only 5->e and by definition there must be a path between any two vertices. Any path from e->...->6 that includes 5->e can be done without it because it must include e->6 after it (e->...->5->e->...->6)).

    e->...->6 must have a length of a multiple of k because then we would have a cycle of length not a multiple of k.

    (why? We can go from 5->6 in 1 move, or we can go from 5->e->6 in |e->...->6|+1 moves. We know we have a cycle of length k through 5->6 so |0->...->5| = 5 and |6->...->0| = k-5-1 so |0->...->5|+|5->e->...->6|+|6->0| = lk. then (5)+|5->e->...->6|+(k-5-1)=lk then |5->e->...->6|=(l-1)k+1)

    So every path must conserve this coloring property and this is the only property required. (proof: collapse every node of the same color into a single node and conserve edges the only cycles remaining are of length k, longer cycles just represent going around this graph more than once).

    Now we can just add edges from k -> k+1 as needed to solve the problem.

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

I had different solutions for both div2 C and D

for C it's a completely different one, I used the following sort

sort(id,id+n,[](int lt,int rt){
            pair <int,int> lM = {max(a[lt].first,a[lt].second),min(a[lt].first,a[lt].second)};
            pair <int,int> rM = {max(a[rt].first,a[rt].second),min(a[rt].first,a[rt].second)};
            return lM < rM || (lM == rM && a[lt] < a[rt]);
        });

for D, Instead of building a graph I used a minimum segment tree to build the distance array so let's say we got d[i] = get(i,n), then we update seg(b[i],min(d[b[i]],d[i]+a[i]))

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

    Yes, task D2D has a solution with a Segment Tree, some participants of the olympiad and rounds wrote it, but it seems to me that the solution with Dijkstra looks more concise :)

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

For Div2 C, I initially tried to sort any tuples by the following condition. Consider the two possible arrangements [tup1[0],tup1[1],tup2[0],tup2[1]],[tup2[0],tup2[1],tup1[0],tup1[1]] and in whichever arrangement the number of inversions is less I put that first. I got wrong answer on testcase 1123.I saw @Dominater069 also try to do the same initially. Can someone please explain why this solution is wrong?

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

    I had done the same thing initially. I suggest you read the following if you are not aware of transitive conditions for sorting.

    Exchange argument: Suppose there is a correct arrangement of the arrays. The editorial proposes a solution that says the arrangement created by sorting based on sum. We now only have to prove that any optimal arrangement can be transformed into the exact arrangement based on ascending sum, without worsening the answer.

    Transitivity: Now the condition of sum is transitive, i.e. sum(a) < sum(b) and sum(b) < sum(c) means sum(a) < sum(c). Now, if the correct arrangement has a pair of indices which doesn't follow this sum order, then we can argue that there is at least one adjacent pair such that they are out of order. The proof is simple. Assume there are non-zero number of elements between the closest pair of out of order pair, hence all the elements in between them are individually in correct order with either of them. Pick a random element x in between them. a < x and also x < b, so it must be that a < b, but we just assumed a > b. Hence the closest pair cannot have correct order elements in between them.Now when we flip the order of the two adjacent arrays, their ordering doesn't matter to the rest of array, but only on the relative order of the two adjacent elements which we show can be flipped without worsening the solution. We can keep arguing and flipping adjacent pairs until there is no pair out of order. Hence we can transform the correct arrangement to our preferred arrangement without worsening the answer.

    Since sorting by (min, max), (max, min) or sum are all transitive conditions, all of them have a similar exchange argument and are all correct.

    TL; DR: The count of inverse for ab and ba is not transitive and it cannot be guaranteed that the optimal answer will have adjacent out of order pairs (ordering based on Inv(ab) < Inv(ba)), if they are not adjacent then swapping them affects all the elements in between and thus it cannot be guaranteed to not worsen the answer.

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

      Such a nice explanation! I didn't actually think about how sorting works!. Thanks a lot. Here is a testcase for anyone else who will read this in future after having made the same mistake as me. [[3,3],[4,1],[2,2]]

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

      silly question please forgive and answer : how exactly did we show that swapping the 2 adjacent out of order pair will not increase the inversion between them ? is it just be trying some cases ? it's clear that it will not affect the left or the right part of the array but what about the 2 pairs them self ?

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

        yes it's casework only, and can be proven by brute forcing all possible cases. There is no general theorem regarding this, for example the order by summation heuristics becomes untrue for sizes starting from 3.

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

I feel like the test cases on D1C are quite weak because I just accepted it with a simple $$$O(K^2)$$$ brute force that checks if the two pairs of counting arrays are equal for any cyclic shift.

On the other hand, I assume it will be hard to generate such a test case if people construct the adjacency matrices and run DFSs differently because this will introduce some randomness in the resulting counting arrays, although that is not the case since most people just run DFS starting from vertex 1 (that is what I did in my accepted submission 287195742).

Was there an attempt to create some test cases against such an obvious brute force?

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

    Uphacked. Also, I think it's not hard to prepare a few of such cases with different "shifting" of the node numbers so that these "lucky" codes cannot pass. Since its average number of iterations would be something like $$$\cfrac{K^2}{4}$$$, it's very unlikely for them to run in the TL even for like 2 of such cases.

»
4 недели назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
// this is code
#include<iostream>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n,k;
        cin >> n >> k;
        int arr[n];
        
        for(int i=0;i<n;i++)
        {
            cin >> arr[i];
        }
        
        int temp =0;
        
        if(k%n==0)
        {
            temp = k/n;
        }else
        {
            temp = k/n + 1;
        }
        int count =0;
        for(int i=0;i<n;i++)
        {
            if(arr[i]<temp)
            {
                count++;
            }
        }
        
        int ans = count + k;
        cout << ans << endl;
    }
    return 0;
}

anyone, can you find where will it fails.

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

isn't constant C in problem 1D just $$$200000 + 1$$$, not $$$200000 \times \left( \frac{100}{99} \right)$$$

UPD: I think my claim is wrong, but it gets AC with $$$C = 200000$$$

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

Use brute force with O(K^2) time complexity to check the cyclic shift in Div.1 C can be accepted. Can it be proved right or just there isn't any hack yet.

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

Hacks to D1C have got Unexpected verdict. Ormlis can you check the validator?

link

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

    Yes, sorry about this. It seems we didn't have good tests against cyclic shift checking in O(k^2), and you hacked one of the solutions, that was marked correct in polygon.

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

2023D - Many Games There is statement $$$W\cdot (100 - p_i) > 200000$$$. It's not a simple one.

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

    About your analysis and your commentary about checking if something is minimum/maximum, you only need to check if $$$f"(x)$$$ is greater/lower then 0 at the points where $$$f'(x)$$$ equal $$$0$$$. This makes your analysis easier, as $$$f"(x)$$$ only assumes the sign required to be maximum overall $$$x > 0$$$. From this you only needs to compute $$$f(1)$$$ and $$$f(99)$$$ to check the inequality, removing the need to verify points with $$$f'(x)$$$ equal $$$0$$$ for $$$x > 0$$$.

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

In 2023B Skipping tutorial above, can anyone help me explain why we are allowed to do this "Now we are allowed to visit each problem as many times as we want"?

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

    It's because we defined the subproblem as we can move on to each problem, no matter if we already solved them or not.

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

      Thanks for your answer. But could you let me know why " no matter if we already solved them or not." In the problem description, we can not visit the problem which was previously submitted or skipped

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

        What you are mentioning is the constraint on the main problem, while this sentence is based on the subproblem that we just newly defined. We first solve the subproblem without the constraint, and then verify that the subproblem indeed solves the original problem.

        Once we solve the subproblem where we can visit the same vertex multiple times using shortest distance algorithms, we also know that it guarantees that each vertex is visited at most once (because visiting a vertex multiple times never helps with improving the shortest distance), so we see that it indeed does not matter if we're trying to visit the same vertex multiple times or not. Therefore, going back to the main problem, if we reach to a certain problem $$$i$$$ with the least penalty possible, we can then solve all unvisited problems with index $$$\le i$$$, receiving the prefix sum of the scores minus the penalty as the total score.

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

How do you generate such graphs for problem div1C ,or do you just originate all cyles from the same node.

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

Can skipping problem be solved by linkedlist which will point to next index for traversal if we have skipped some indices in between? FOR EXAMPLE: If initial list is like -1 <- 1 <- 2 <- 3 <- 4. (1 based indexing used). Now if Q3 is skipped then its corresponding next index i.e. 2 will be unlinked and linked to 1. Then the new list will be -1 <- 1 <- 1 <- 3 <- 4. WIll this handle recursion and dp if I backtrack results of list while coming back?

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

Can someone pls tell why i got runtime error in pretest 4 for Div2 C , i sorted the array based on sum of elements
https://codeforces.net/contest/2024/submission/286970228

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

My solution for D2C was sorting by the smallest element of the tuple. I thought this worked because you can only control the inversions of one element of the tuples when swapping. This differs quite a bit from the official solution, so I was wondering if my approach was actually correct or if the testcases were simply too weak.

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

My approach to D2C was sorting the array by the smallest element in the tuple. I was wondering if this is an actual solution to the problem, or if the test cases were simply too weak?

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

What's the necessary proof for D1C? Like if there doesn't exist some cyclic shift that satisfies, the answer is always false? And how to prove that?

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

What's the necessary proof for D1C? Like if there doesn't exist a cyclic shift so the frequencies are the same, then there's no solution? I think the editorial only shows sufficiency.

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

Can anyone please explain me the intuition behind Div2C, I am unable to derive the intuition. I saw a tutorial and it just said to think of max-min of pairs. But how and why did we arrive to this max-min of pairs?

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

how would you do the concatenation of arrays question if there were 3 numbers in each array?

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

.

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

We can solve D problem (Many Games) faster. My optimization: for each element with p probability and w winning sum we can only choose winnings which sum we can improve.

Formula: x < p*(x + w) => x * (1 — p) < p*w => x < p*w/(1-p). x is the sum of set to which we can add our element.

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

Problem — Buying Lemonade
In test case 2 I am getting this error "wrong answer 958th numbers differ — expected: '8', found: '7'". Since large test case gets truncated, how do I debug this?
Submission

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

In C, why the arrays can't be sorted in order of the number of inversions of two adjacent arrays. Just like this:

sort(a.begin() + 1, a.end(), [&](pll x, pll y) {
        ll cx = 0, cy = 0;
        vll vx; vll vy;
        vx.push_back(x.first);
        vx.push_back(x.second);
        vx.push_back(y.first);
        vx.push_back(y.second);

        vy.push_back(y.first);
        vy.push_back(y.second);
        vy.push_back(x.first);
        vy.push_back(x.second);
        for(int i = 0; i < 4; i++) {
            for(int j = i + 1; j < 4; j++) {
                if(vx[j] < vx[i])
                    cx++;
                if(vy[j] < vy[i])
                    cy++;
            }
        }
        return cx < cy;
    });

Is there any counterexamples?