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

Автор vovuh, история, 6 лет назад, перевод, По-русски

1343A - Candies

Идея: vovuh

Разбор
Решение

1343B - Balanced Array

Идея: vovuh

Разбор
Решение

1343C - Alternating Subsequence

Идея: vovuh и MikeMirzayanov

Разбор
Решение

1343D - Constant Palindrome Sum

Идея: MikeMirzayanov

Разбор
Решение

1343E - Weights Distributing

Идея: MikeMirzayanov

Разбор
Решение

1343F - Restore the Permutation by Sorted Segments

Идея: MikeMirzayanov

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

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

How Problem D can be solved using scanline algo?

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

Thanks for the tutorial <3

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

For Question D is the overall complexity O(k(n+k))? Since the procedure needs to be repeated for each possible x

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

Can anyone tell me what am I doing wrong in problem E? Here's my submission 77588849

In the graph, I am calculating the minimum distance from a to b, and then b to c. During this, I am storing the frequency of the edges I will visit, and then later assigning the least price to the edge with the highest frequency.

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

    your code will WA answer for the test case 1 5 5 3 1 5 10 5 6 100 80 3 2 1 2 1 4 5 4 5 3 answer is 32 your code is giving 101 means that here you will go from a to b then from b to c via a that will give minimum answer

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

    Here a test case that resembles the graph of 2nd example in the problem.

    1 7 9 1 5 7 3 3 5 10000 10000 10000 10000 10000 10000 1 2 1 3 1 4 3 2 3 5 4 2 5 6 1 7 6 7

    The optimal output should be 1->7->6->*5*->6->7 then you assign these prices 5,3,3 to get the answer as 5 + 2*(6) = 17.

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

    You cannot do the question on basis of only considering shortest from A to B and then shortest from B to C separately. Consider smallest path from A to B(length s)and there is another path from A to B(length s+1)which has only one more edge then the smallest one.Suppose that path contains C, so that is more advantageous and we need only smallest s+1 prices while with the shortest path we will need then s+k prices (k distance of B from C).

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

    Thank you everyone for helping me figure out my mistake. I really Appreciate it

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

Can someone explain me solution to problem E in simpler words.

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

Anyone why my code didn't got accepted..??

https://codeforces.me/contest/1343/submission/77549512

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

For E why would the optimal path only have 1 or less intersection?

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

Finally solved one question after joining here few months back in rated. Yaay. Small step forward.

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

In problem F, why would the permutation be unique?

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

Why is the blog of the solution called Editorial in this blog but called Tutorial here in the contest?

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

Thanks for the tutorial. But I don't understand the tutorial of problem E, can anybody help me please?(Please explain me in simpler words) Thank u very much!

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

Can anybody explain problem F I am not able to understand the tutorial

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

Why do we need to convert to binary representation, while we can just add 2^0 to (2^0 + 2^1 + ... + 2^(k-1)) = 2^k :D

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

In Problem D, Can anyone explain why (n/2) — prefix(x) is needed for calculating part 3 of the solution?

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

In problem E, my approach is —

  1. Find the set of nodes that lie on the shortest path from a to b, stored in res1.

  2. Find the set of nodes from lie on the shortest path c to b, stored in res2.

  3. Find the common nodes (if any) that lie from b, let this be equal edges

  4. Find the distinct edges, let this be diff edges = res1.size() + res2.size() — 2 * equal.

Then I assign the min values to common edges and the next min values to other diff nodes.

I am getting WA on Test-4. Can anyone tell me where I am doing wrong ?

I get — wrong answer 320th numbers differ - expected: '4', found: '6'. How to see the 320th tc ?

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

    I did the same mistake and got the same WA on the same test case :D. The problem is that you are assuming that the shortest path from a->b->c will comprise of shortest path a->b and shortest path b->c, which is not true..

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

      Why it is not true?

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

        Well I haven't worked it out mathematically, but if you think intuitively, you have to maximize the number of repeating edges while also minimizing the total distance traveled. So it is possible to construct a graph in which a longer path gives you more number of repeated edges, which reduces the total cost, as compared to the shortest path consisting of all distinct edges.

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

        Hey, this is one such case in which this method produces wrong answer — This has been pointed out by someone in the comments above —

        1
        5 5 3 1 5
        10 5 6 100 80
        3 2
        1 2
        1 4
        5 4
        5 3
        

        The optimal answer to this will be 32.

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

In the D problem. How did we get the value (n/2)-prefx and the final equation also?

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

    Since each element of the array lies between 1 and k, the range of values [min(a[i],a[n-i+1])+1,max(a[i],a[n-i+1])+k] will include the pairs for which the sum equals x as well. Hence pref(x) represents the pairs for which AT MOST 1 needs to be changed. n/2 is the total. Subtract pref(x) from it, we will get the ones which require both elements to be changed. Final equation we need number of changes = (at most 1 change required — no changes required) + 2*(number of pairs which require both elements to be changed)

    Last term multiplied by 2 because 2 elements are changed.

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

Can someone tell how can the solution is found out because i am not getting ++pref[] part code and further code so can anyone explain how the results are generalized..? Problem D

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

    It is on of the popular techniques, it can update in O(1) time and changes are accumulated at the end by calculating the prefix sum.

    The range is updated using the index bounds. Consider you want to update the range [l,r] then that can be done adding the +1 to the left bound and -1 at the right corner. So whenever you would be calculating the final results, the following thing happens -:

    1. The +1 is propagated in the range [l, r] since you are adding the previous element to the present element.

    2. The -1 handles the stopping case at r + 1 and now the +1 is neutralized by -1.

    Once this array pref is generated, you are now with sum values which would require just a single modification to reach sum.

    Since the answer for this overall problem will be :

    1. The number of pairs in which both elements need to be changed.
    2. The number of pairs in which a single element need to be changed.

    For the 2nd one, cnt[i] (already having the sum of i beforehand) — pref[i] (which need one element modificationto reach sum i)

    For 1st one, the remaining pairs will be the one with 2 modifications, (n / 2) (Total pairs) — pref[i] (sum with one modification to reach i).

    Multiplying it by 2 since two modifications are required.

    Now try to calculate minimum by iterating over all the possible values of sum [2, 2k].

    Sorry for the bad representation. I hope it helps.

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

hey can anyone tell me why are we doing --pref[max(r1, r2) + 1] in problem D? also why are we calculating prefix sums?

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

    for any pair a[i] and a[n-i-1] we can make it equal to some sum x by changing at most one element a[i] or a[n-i-1] if sum x is in range min(l1,l2) to max(r1,r2). but as sum goes to max(r1,r2)+1 we need to change two elements

    we are calculating prefix sum because above argument follows for all sum values that are in range min(l1,l2) to max(r1,r2)

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

Video editorial of D. Click here

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

Here is a solution with Explanation for D (Check Here)In case anyone is interested

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

Solution of D using Difference Array https://codeforces.me/contest/1343/submission/77550669

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

In Problem E, can anyone tell me what should I do if a point is visited again? how would I know if I have assigned an edge some weight more than once? Thanks in advance.

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

    You can ignore overestimates, because it can be shown that vertices that cause overestimates are never the optimal choice for intersection.

    A very rough "proof": if the editorial's algorithm assigns more than one cost to a set of edges and thus overestimates the cost, it means that at least two paths among $$$x \rightarrow a, x \rightarrow b,$$$ and $$$x \rightarrow c$$$ overlap. The overlapped edges would form a path from $$$x$$$ to some other vertex $$$y$$$. In this case, $$$y$$$ is always a better choice of intersection.

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

why my submission is not showing and also final standing not showing I have solved first 4 qus

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

How can we use binary search in problem D?? It has tag of binary search. I found out that for making sum of pair from 2 ..... 2*k does not yield a function that has one global optimum...so how we can use binary search on it??

Here is one of some possible arrangement :
n=10 k=5
array=1 4 2 3 5 2 3 1 4 2
sum  = changes required
2       = 8
3       = 5
4       = 6
5       = 5
6       = 4
7       = 4
8       = 6
9       = 8
10     = 9

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

    I built a vector that holds the minimum value every pair can take with one change, and a vector that holds the maximum value every pair can take with one change. Fix a target 1 <= x <= 2k that you want every pair to equal after your changes. The number of pairs whose min is > x will require 2 changes, as will the number of pairs whose max is < x. You can binary search for the number of pairs that fulfill these conditions, using something like lower_bound(mins.begin(), mins.end(), x). You'll can also see that a pair cannot fulfill both of these conditions simultaneously, so we don't double count.

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

Задачу F можно решать за O(n^2*log(n)). Всего лишь нужно перебирать не все элементы, которые мы хотим ставить на первую позицию. На первую позицию нужно ставить тот элемент, который встретился один раз в заданных отрезках, а таких элементов может быть только 2.

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

New to codeforces here, can anyone tell me yesterday I solved 3 problems here but now RED is showing on B and C (even though code is same as editorials) WHY?

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

Can anyone suggest more problems like D? The prefix sum approach seemed very cool

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

In problem E why are we checking dist(a,x)+dist(b,x)+dist(c,x)≤m ?

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

If someone knows how to solve Problem D using Scanline Please mention your code or any good resources to learn it will be appreciated :)

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

Can anyone please explain the segment tree or BIT based approach in problem D that would be helpful??

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

can someone explain what problem c actually meant?? still didnt get the problem clearly. thank u.

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

    The given array will consist of some positive and some negative elements. An alternating subsequence will consist of alternating elements (pos,neg,pos,neg... or neg,pos,neg,pos.... and so on). you need to take the max length of alternating sebsequence and find its sum. Remember there could be multiple such subsequence of max size but you need to print the max sum among all.

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

for D, we can also just check for only those sums that the pairs already make instead of checking all values from 2 to 2*k.In worst case,the maximum value will be n/2, when one element from all the pairs have to be changed.

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

typedef long long int ll;

include

include <bits/stdc++.h>

include

include <math.h>

include <string.h>

using namespace std; int main() { int t; cin >> t; while(t--) { ll n; cin >> n; ll arr[n]; ll brr[n]; for (ll i = 0; i < n;i++) { cin >> arr[i]; if(arr[i]>0) brr[i] = 1; else brr[i] = -1; } ll sum = 0; for (ll i = 0; i < n;i++) { ll lar = arr[i]; ll j = i; int val; if((brr[i]*brr[j])==brr[j]) val = 1; else val = 0; while(j<n && val==1) { lar = max(lar, arr[j]); j++; } sum = sum + lar; i = j — 1; } cout << sum << "\n"; } }

Whats wrong in my code ITS FOR QUESTION C

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

Can anyone please explain how to do problem D with binary search, i tried but couldn't find a way to do it

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

Can anyone please explain D to me in simple terms? Would be really grateful as I'm understanding parts of the solution but not whole. Thanks.

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

In contest, I got Accepted at the problem D, but when the system tested I got TLE on test 8, but in contest it passed :(. The only thing that I changed today was instead of long long I put int and passed. Why that happened?

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

    During the contest, not all test cases are run. You would have got the correct answer for the tests that were run during the contest. After the contest was over, when all test cases are run, there must be some test cases in which your code didn't run in time. Changing long long to int would have solved the problem because computation on integers takes about half as much time as computation on long long integers. This is because in some machines, the size of the CPU register is 32 bits and long long takes 64 bits. I think it is also dependent on the compiler but not sure.

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

Question F can be solved in O(n^3) without the log factor. And according to my solution, once we got the permutation, we need not check it again whether it satisfies with the input segments. My submission

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

https://codeforces.me/contest/1343/submission/77564353 This is my solution for D which I submitted during contest. It gave me TLE in system testing on TC11. Now i copied exactly the same code and submitted it after the contest(and after the system testing) https://codeforces.me/contest/1343/submission/77619357. This is the link for the same. It is Accepted by the system. moreover i have submiited the same code 3 -4 times after contest it is showing AC every time. Now can somoene please explain to me why is all this happening and if my code is AC will i get marks for it??

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

Can anyone please tell me why I am getting wrong answer on test case 4 in problem E

My Approach :-

  1. Find all the edges on shortest route from a to b using bfs

  2. Find all the edges on shortest route from b to c using bfs

  3. Sort the price array

  4. Assign lowest prices to common edges in path from a to b and b to c

  5. Assign lowest prices among the prices left to remaining edges in routes

Code Link :- https://codeforces.me/contest/1343/submission/77562702

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

Why aren't editorials posted here?

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

In 1343A why if I place break statement after if loop it's not working??

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

For E i tried running bfs from a to b and then b to c and marked the used edges in a map and then counted edges having frequency two = repeated_edges and added these many least weighed edges twice and others once from the weight array but it is failing on tc — 4 case 320 can someone please point out the error.

https://codeforces.me/contest/1343/submission/77633200

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

vovuh IN problem: (F) Restore the Permutation by Sorted Segments

for last test case
5

2 2 5

3 2 3 5

4 2 3 4 5

5 1 2 3 4 5

why 1 4 3 2 5 is wrong answer (correct as per test case:2 5 3 4 1)

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

min(ai,an−i+1)+1;max(ai,an−i+1)+k , why is the left side not mini(ai,an -i + 1) — 1, why +1

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

    let {a[i],a[n-i+1]} be the pair of elements, then whats the minimum sum of this pair possible by replacing at most 1 of the two elements so the operation cost is 1, so we will take the minimum of the two pair unchanged and will change the maximum of the pair to 1 as the minimum number we can replace to is 1. So it becomes min(a[i], a[n-i+1])+1. Hope it helps.

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

Could anyone (maybe vovuh) please look my solution of D and help me hack this solution, if its possible!

Idea is very simple: Just try some values of sums (i.e. x) close to K, along with some most frequently occuring sums.

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

    Can you please help me what is wrong in my solution for D (Brute Force), I'd be grateful:

    #include<bits/stdc++.h>
    using namespace std;
    
    int numberOfChanges(vector<pair<int, int>> v, int k){
        int sum= 0;
        for(int i=0; i<v.size(); i++){
            if((v[i].first+ v[i].second)==k) sum+=0;
            else if(v[i].first >=k && v[i].second >=k) sum+=2;
            else sum+=1;
        }
        return sum;
    }
    
    int main(){
        int t;
        cin>>t;
        while(t--){
            int n, k;
            cin>>n>>k;
            int A[n];
            for(int i=0; i<n; i++){
                cin>>A[i];
            }
            vector<pair<int, int>> v;
            for(int i=0; i<n/2; i++){
                v.push_back(make_pair(A[i], A[n-i-1]));
            }
            int count, min_count=INT_MAX;
            for(int i=2; i<=2*k; i++){
                count= numberOfChanges(v, i);
                if(count<min_count) min_count= count; 
            }
            cout<<min_count<<"\n";
        }
        return 0;
    }
    
»
6 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

What is the proof for E, that the optimal path always looks like this :a→x , x→b, b→x and x→c ?

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

    Let the paths $$$a = v_1 ... v_n = b$$$, $$$b = v'_1 ... v'_m = c$$$ be optimal. Choose minimal $$$i$$$ such that $$$v_i \in {v'_1 ... v'_m}$$$, say $$$v_i = v'_j$$$. $$$i \lt = n$$$ since $$$v_n \in {v'_1 ... v'_m}$$$. Let $$$P_1 = (v_i, ... ,v_n), P_2 = (v'_1 ... v'_j)$$$. Let $$$rev(P)$$$ for path $$$P$$$ be the reverse of that path.

    There are cases:

    $$$P_1 \not = rev(P_2)$$$. WLOG say the length of $$$P_1 \geq $$$ length of $$$P_2$$$. Then we can replace the $$$ab$$$ path with $$$v_1, v_2 ... v_{i - 1}, rev(P_2)$$$. This new $$$ab$$$ path is not longer then the old $$$ab$$$ path so we can do this.

    $$$P_1 = rev(P_2)$$$. Then take $$$x = v_i$$$ and we have paths $$$a \rightarrow x$$$ is $$$v_1 ... v_i$$$, $$$x \rightarrow b$$$ is $$$v_i ... v_n$$$, $$$b \rightarrow x$$$ is $$$v'_1 ... v'_j$$$ and $$$x \rightarrow c$$$ is $$$v'_j ... v'_m$$$.

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

https://codeforces.me/contest/1343/submission/77590860 problem D, can anyone tell me an anti-testcase?

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

(if dist(a,x)+dist(b,x)+dist(c,x)≤m). can anybody please explain this line to me in editorial of problem E?

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

Finally reached expert...Thanks for the contest.. Qestion D was really nice ..

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

problem E:why is the condition dist(a,x)+dist(b,x)+dist(x,c)≤mnecessary?

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

I created a test case which hacked the solution in tutorial. Is the std wrong or my test case illegal?
the test case: 1 6 2 1 3 3 1 3 4 2 1 4 2 2 5 2 2 6 The std output nothing. Thanks very much for testing my test case

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

I was thinking the same about problem E. But I was and still in doubt that How we can assure that path a -> x and x -> c will not have any common edges.

As the tutorial is saying: "like three straight paths with one intersection point x", I am not getting this, How can we assure about three straight paths always?

Could somebody help me with this? Thanks!.

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

    x->c can have edges which are common with x->a or x->b . If it's x->a, then we have 2 cases: 1) x->c has all edges from x->a (path is x->a->c and common edges are the edges from x->a) or 2) there is some point y in between 'a' and 'x' such that the edges from x->y is common (i.e x->y->c, a->y->x and common edges are the edges from y->x). In the first case, if 'x' is not 'a', then having x=a will always give better answer as x->a +x->b + x->c will be smaller and you have a longer prefix x->b. In second case, you can have x=y which will give a smaller answer because of the same reason mentioned above. Similarly, you can work out for edges which are common to x->b. The point is that the algorithm will find surely find the optimal answer (x=a or x=y in above case) if there exists one.

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

Can someone explain the following code in Problem C — auto sgn = [&](int x) { if (x > 0) return 1; else return -1; }; how auto keyword is used here and materials to read to understand this code. Please!

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

Can somebody please explain why I am getting WA on E Submission Link

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

    Final ab & bc paths not always necessarily shortest paths between a-b or b-c. One of the longer paths could have more vertexes in common thought better weight sum. Plus, Dijkstra has o(n*ln(n)) complexity and should fail on big inputs since, as stated in the editorial, for this problem it is sufficient to make liner 5 passes.

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

      I have actually calculated shortest paths from a-b ,b -c, a-c , if path from len(a-b) = len(a-c) + len(b-c) then c occurs in one of the shortest path from a to b and that path should be considered for optimal soln. otherwise the path from a-b (shortest ) and b-c shortest is considered .Though due to TL the soln might get TLEd but I want to know If the above approach is incorrect!! :)

      BTW, Thanks for the reply !!

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

        Yep, it is incorrect. Shortest a-b path does not always appear in the best possible solution. If you have p[weights] = {1,..(9 ones)..,1,100,100,100...} and graph: 1-(5edges)-6-(5edges)-11, and from vertex 6-(6edges)-x=a,c (x connected to both a and c by 1 edge each), then a,b,c = 1, 6, 7. Shortest paths a-b and b-c are 5 vertexes each. But since you have only 9 ones, your result with the shortest paths would be 109. But if you'll go through point x, your result ould be 1+6*2+1 = 14. Or through the point a with result 12.

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

        Or imagine rhombus with vertexes a,b,c,x. With 10 edges between a and b, 10 between b and c, and with 6 edged between each pair: a-x, b-x, c-x. If you have only 19 ones and a lot of hundreds among edge weights, your cheapest path would lay through point x, and it has no common edge with either of shortest paths a-b or b-c.

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

Nice editorial! I really enjoyed the problems.
Here is a submission for problem F with comments. I think it's clear and easy to understand . But if there are questions feel free to ask. https://codeforces.me/contest/1343/submission/77673993

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

HI I have a question related to Problem A:

geometric sequence tells that = 2^(k-1)

but in the tutorial you said: ((2^k)-1)

anyone please explain???

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

How Problem D can be solved using Binary search?

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

    I built a vector that holds the minimum value every pair can take with one change, and a vector that holds the maximum value every pair can take with one change. Fix a target $$$1 \lt = x \lt = 2k$$$ that you want every pair to equal after your changes. The number of pairs whose min is > x will require 2 changes, as will the number of pairs whose max is < x. You can binary search for the number of pairs that fulfill these conditions, using something like lower_bound(mins.begin(), mins.end(), x). You can also see that a pair cannot fulfill both of these conditions simultaneously, so we don't double count.

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

auto sgn = [&](int x) { if (x > 0) return 1; else return -1; }; what does this code do ?

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

In problem F the permutation is not necessarily unique! In general, if all given intervals are of length 2 the permutation can be reversed and still be correct. Those should be the only 2 possible permutations

One can also reconstruct the array from the last element to the first: The last element can only occur in one segment and there can be at most two elements which occur only once (the last and maybe the first). So if there is only one element it has to be the last. If there are two we can just test both but fixate the other one as the first element. If the first element is fixed we will only find one other element which occurs only once at every moment so we will find at most two permutations (those are the only two possible permutations). We can check both for correctness and print the right one.

My Implementation: 77696766

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

For problem, 1343E — Weights Distributing, am getting wrong answer on test 3, Error says: 35th numbers differ — expected: '4', found: '3' Any idea why? Not able to get the failing test case as it was too long My solution link

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

why difficulty of problem F is 2800? lol, it is strange, who set difficulties?

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

what is the significance of this statement "It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 (∑n≤2⋅105)"

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

What's wrong with B problem editorial explaination?
In Editoral vovuh wrote that->(This array is almost good except one thing: the sum in the right half is exactly less than the sum in the left half. So we can fix it easily: just add n/2 to the last element.)

But in tutorial code this line is look like ->
(cout << 3 * n — 1 << endl;)

How (3*n — 1 == n/2)?

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

Hello, in problem C, vovuh has something called sgn, is that a function or something else? Could someone explain it or what it is called so I could find a tutorial?

Thanks in advance

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

1343E - Weights Distributing Can anyone help me in my code it says wrong ans for test 4 https://codeforces.me/contest/1343/submission/77737942

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

For problem E, why can we ignore dist(a,x)+dist(b,x)+dist(c,x)>m case? Don't say array index out of range, we can use other methods compute this

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

Did anybody solve D using Segment Tree, is it possible?. UPD Found

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

Can someone tell me about assert function more deeply? this function is being used by editorial solution maker??

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

How to solve problem A?

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

I didn't understand the tutorial of F. Any help would be appreciated.

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

    First number in permutation would always be in 1 and only 1 segment of size 2. Grab all elements from 2-sized segments and check if there can be formed permutation if it would be the first element: first, exclude it from every segment where you find it — after this, there must be only 1 segment with size "1". This will be the second number. Take this number and exclude it from every segment, now there must be only one segment of size 1. This will be the third number... and so on. When found sequence — check it. If it's good — output, else search next number to be first.

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

anyone did problem D ? with binary_search approach?..please help

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

Why pref means at most 1 replacement instead of exactly 1 replacement in Problem D?

I've tried to understand it for three days.

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

    Because when we increment one in the segment: [min(a_i, a_{n-i+1}) +1, max(a_i, a_{n-i+1})+k )

    We are also incrementing the position a_i + a_{n-i+1} and the x made by a_i + a_{n-i+1} we already have for free.

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

Can anyone give me the python code to make the prefix array for problem D?

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

Why Problem E can't be solve with two bfs? one bfs from a to other nodes and other bfs from c to other nodes and then I can simulate the junction point of a and c with this two distance, but it is showig WA

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

In the Problem E, it says:"There are no loops or multiple edges in the given graph". Does the "loops" here actually mean "self loops"? In my opinion, the second example contains "loops". Am I wrong ?

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

Easy implementation of F

78569543

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

What's the 373th TestCase of Test 2 ?

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

Wouldn't the complexity of solution provided for F be O(n^4*logn) as comparing sets take linear time? MikeMirzayanov

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

Can someone explain what is meant by "the parities of halves won't match" in tutorial of problem B?

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

    The sum of numbers in the first half is even, since all values are even. If the size of the half array is odd, then the sum of the second half will be odd, too. Since the sum of the halfes must be same this leads to no solution possible.

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

In Alternating Subsequence problem, one test case is [-2 8 3 8 -4 -15 5 -2 -3 1]. The longest alternating subsequence is [-15 5 -2]. Hence the answer should be -12. But given solution is [-2 8] => 6. Please help me with this.

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

D can also be solved using policy based DS. https://codeforces.me/contest/1343/submission/97821782

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

n &1 what do you mean by this ??

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

Problem E is so good