bestial-42-centroids's blog

By bestial-42-centroids, history, 10 months ago, In English

Thank you for participating in our round ! We hope you enjoyed our problems. Feel free to discuss them in the comment section :)

/!\ The solution codes will be available in a few minutes

UPD: The solution codes have been added ! UPD2: The solution codes links are fixed ! Sorry for the inconvenience.

2128A - Recycling Center

Solution
Rate the problem

2128B - Deque Process

Hint1
Hint2
Solution
Rate the problem

2128C - Leftmost Below

Hint
Solution
Rate the problem

2128D - Sum of LDS

Hint1
Hint2
Solution
Rate the problem

2128E1 - Submedians (Easy Version)

Hint1
Hint2
Hint3
Hint4
Hint 5
Solution
Rate the problem

2128E2 - Submedians (Hard Version)

Hint1
Hint2
Hint3
Solution
Code
Rate the problem

2128F - Strict Triangle

We shorten $$$\text{dist}_w$$$ by $$$d$$$. We denote $$$d_L$$$ as the distance when every edge has weight $$$l_i$$$, and $$$d_R$$$ as the distance when every edge has weight $$$r_i$$$.

Hint1
Hint2
Hint3
Hint4
Hint5
Hint6
Solution
Rate the problem
  • Vote: I like it
  • +206
  • Vote: I do not like it

»
10 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

Auto comment: topic has been updated by bestial-42-centroids (previous revision, new revision, compare).

»
10 months ago, hide # |
 
Vote: I like it +23 Vote: I do not like it

wow instant tutorial!

»
10 months ago, hide # |
 
Vote: I like it -12 Vote: I do not like it

Thanks for the quick tutorial! Very good contest, I found problems level very well distributed. There wasn't a big gap in difficulty between consecutive problems, at least until E1. Well done!!!

»
10 months ago, hide # |
 
Vote: I like it +50 Vote: I do not like it

C and E2 are cool, but neither D nor E1 should be in a div2

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +2 Vote: I do not like it

    I humbly disagree with your opinion. In my opinion, D was an excellent problem.

    C was way too easy IMO.

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Agreed..

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it +5 Vote: I do not like it

      the problem with E is, it is similar to recent div3 G1/G2

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it -11 Vote: I do not like it

      if C was way too easy IMO, under which topic in IMO could it be appeared.

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        IMO is not some topic. sorry for confusion. here I used IMO in context of "In My Opinion".

        If you are looking for topic to solve C, I would say try to see pattern. You can observe a pattern that If minimum of the prefix part from 0 to i-1 is 'm' , then in the index 'i' you can not add more than 2 * m — 1

        How ? ( first you would add m-1 to index 'i', and then you would add 'm', so total 2 * m — 1 ).

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I got stuck at ABC, ironically. Nevertheless, D and E1 were fun!

»
10 months ago, hide # |
Rev. 2  
Vote: I like it +12 Vote: I do not like it

You can now rate the problems in the editorial !

Auto comment: topic has been updated by bestial-42-centroids (previous revision, new revision, compare).

»
10 months ago, hide # |
 
Vote: I like it +55 Vote: I do not like it

1486D - Max Median

problem E1 is similar to this

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +19 Vote: I do not like it

    isnt it the exact same

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Indeed it's the same similar problem though in this div2 you check

    pref[r] — pref[l — 1] >= 0

    while that problem passes with pref[r] — pref[l — 1] > 0

»
10 months ago, hide # |
 
Vote: I like it +19 Vote: I do not like it

E1 was pretty easy comparing to div2 E. I have solved at least 3 problems which uses this similar idea

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Whats the proof for submedian being monotonic for E1?

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    did you get the proof

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      This is my understanding, but it might not be correct. for a sub list and a V, you need to satisfy 2 conditions 1. big condition, the number of elements in the list greater or equal to V must bigger than (|list|+1)/2, which wishes V to be small 2. small condition

      submid want to fit the two conditions, which is not monotonic,for example [6,7,8] k=3, V=7 fit the two conditions, but V'=6 does not

      however for one condition, such as big condition is monotonic the smaller V is, the more likely the big condition to be fitted

      so we can binary search the biggest V to fit the big condition, and we also know the bigger V is, the more likely the small condition to be fitted

      let v be the largest V fits big condition, [ans_l:ans_r] be the sub list. [v, ans_l, ans_r] is the answer. how to prove it?

      we can infer v must be in the sub list if ith<v<i+1th, e[v]+g[v]-l[v]>=0, e[v]=0 (e stands for equal, g stands for greater, l stands for less, "ith" and "i+1th" respectively refer to the i-th and (i+1)-th largest numbers.) let v'=i+1th,l[v']=l[v],e[v']+g[v']=g[v], big[v']>=0 but v'>v The proof by contradiction holds.

      so e[v]>0, l[v+1]=l[v]+e[v] (v+1 stands for i+1th in sub list)
      big[v]=e[v]+g[v]-l[v]>=0
      big[v+1]=e[v+1]+g[v+1]-l[v+1]<0
      g[v+1]=g[v]-e[v+1]
      l[v+1]=l[v]+e[v]
      so big[v+1]=big[v]-e[v]
      because big[v+1] < 0
      so big[v]<e[v]
      so e[v]+g[v]-l[v]<e[v]
      so g[v]-l[v]<0
      so small[v]=e[v]+l[v]-g[v]>e[v]>0
      

      so the small condition is also fitted

  • »
    »
    10 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    Instead you can just binary search on the condition that a median $$$\ge x$$$ exists iff in an array with $$$\text{b}[i] = 1$$$ if $$$\text{a}[i] \ge x$$$ else $$$-1$$$ you have some $$$\text{pref}[r] - \text{pref}[l] \ge 0$$$ with $$$r-l \ge k$$$ and there is nothing to prove. Also a classic trick.

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      This is what I meant by the predicate being monotonic. Essentially: if you know there exists a submedian $$$\geq x$$$, then the largest submedian is $$$\geq x$$$.

      You might ask: what does it have to do with monotonicity ? Well, binary search on the answer can be explained like this:

      You define a function $$$f: \mathbb{N} \rightarrow {0,1}$$$ (note that $$$\mathbb{N}$$$ could be replaced with something else), Assume that function is increasing (so essentially, either $$$f$$$ is constant, either there exists $$$k$$$ such that $$$f(0) = f(1) = ... = f(k) = 0$$$ and $$$f(x) = 1$$$ for $$$x \gt k$$$. Binary search allows you to find that $$$k$$$ i.e finding the last $$$0$$$ (or equivalently, the first $$$1$$$).

      Now, in practice, it means that if $$$f$$$ is an "increasing", "question", you can find the smallest thing such that the answer to the question is YES.

      PS: of course, a similar thing holds for decreasing

      Sorry if it wasn't clear from the editorial

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it +5 Vote: I do not like it

        Yes, I did understand that part. That line did indeed make it clear (editorial is great) that you could binary search on median $$$\ge x$$$. However, after that you talk about something else that is interesting (but I suppose isn't the easiest way to solve the problem) so I'm assuming that's what confused people. In my comment I just wanted to point out that you can ignore all that (although I know you probably included it to provide intuition) and just do the binary search with the sole fact that you have a monotonic predicate.

»
10 months ago, hide # |
 
Vote: I like it +45 Vote: I do not like it

Interesting E2.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

"and will increase $$$d(1,k) + d(k,n)$$$"

I think there's a typo here, we're decreasing the weight of the edge, that can't happen

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by hugopm (previous revision, new revision, compare).

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

thanks for superfast editorial

»
10 months ago, hide # |
 
Vote: I like it +47 Vote: I do not like it

D can be solved with dp too. Because of the constraint $$$ max(p_i, p_{i+1}) \gt p_{i+2} $$$, the $$$ LDS $$$ ending at index $$$ i+2 $$$ will always have one of $$$ p_i $$$ or $$$ p_{i+1} $$$ as the second last element. Hence, we get

$$$ dp_{i} = max(dp_{i-2} + (i - 2) + (i - (i - 2)), dp_{i-1} + (i - 1) + (i - (i - 1))) $$$
$$$ dp_{i} = max(dp_{i-2} + i, dp_{i-1} + i) $$$

This basically means that for jth index, all LDS ending at jth index will increase by 1 hence we get j increments and for all the elements after j, we will get a new LDS of length 1

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +58 Vote: I do not like it

    My solution was also based on dp, though a bit cleaner. One can observe that either $$$p_i$$$ or $$$p_{i+ 1}$$$ is the greatest element on suffix from $$$i$$$. Let $$$dp_i$$$ be the sum of lengths of LDSs for subranges that start at $$$i$$$.

    If $$$p_i \gt p_{i+1}$$$, $$$p_i$$$ is the suffix maximum, so we can always take it as the start of LDS and then find LDS from $$$i+1$$$ independently. Thus $$$dp_i = dp_{i+1} + n - i$$$ (in 0-indexation). $$$n - i$$$ is the number of times $$$p_i$$$ is used in LDS.

    If $$$p_i \lt p_{i+1}$$$, we always take $$$p_{i+1}$$$ in LDS, but not $$$p_i$$$, unless the range is $$$[i, i]$$$, then we only take $$$p_i$$$. So $$$dp_i = dp_{i+2} + n - i$$$, because the total contribution of $$$p_i$$$ and $$$p_{i+1}$$$ remains $$$n - i$$$.

    The answer is the sum of all $$$dp_i$$$

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it +25 Vote: I do not like it

      Neat solution! I included a link to it in the editorial :)

    • »
      »
      »
      10 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it +1 Vote: I do not like it

      Here dp[i] means subranges that start exactly at i or subranges where l >= i?

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it +11 Vote: I do not like it

      If you iterate $$$i$$$ and define and update the dp from the other way around, it would be cleaner too:

      $$$dp_i = dp_{i-1} +1$$$

      or

      $$$dp_i = dp_{i-1} + i$$$

      submission

      • »
        »
        »
        »
        10 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Yeah, that's what I did in contest too submission

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        can you explain why dp[i]=dp[i-1]+1 ???

        • »
          »
          »
          »
          »
          9 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          This happens when (arr[i+1] > arr[i])

          So in this case we know that max(arr[i-1],arr[i]) > arr[i+1] and since arr[i] < arr[i+1] then arr[i-1] > arr[i+1].

          And the other two observations would be — 1. arr[i-1] > arr[i] as arr[i+1] > arr[i]. 2. For any index i, the best possible LDS till index i will have arr[i] as the last element. You can prove it easily.

          Hence basically all the LDS for i+1, will have all the elements of all LDS till i except the last element, the last element will get shifted to index i+1 for every LDS

          Hence, dp[i] = dp[i+1] + 1

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it +12 Vote: I do not like it

      If p[i] < p[i+1] then just dp[i]= dp[i+1]+1. This could be cleaner.

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      genius

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I can't understand why the total contribution of pi and pi+1 remains n — i ,could other friends help me?Thanks.

      • »
        »
        »
        »
        9 months ago, hide # ^ |
        Rev. 2  
        Vote: I like it 0 Vote: I do not like it

        if a[i] is greater than a[i+1], for all subsequences with i+1 as the start , a[i] will be the new addition to all those subseqs in different subarrays made with i as the start , so to all those subseqs , 1 will be added , therefore we add n-i to dp[i+1] ,,but when a[i+1] is greater than a[i] , a[i] adds only one extra subsequence which is itself (because its smaller) ,, so dp[i]=dp[i+1]+1 in that case ,, which can also be written as dp[i]=dp[i+2]+n-i , which is basically the same thing as we use the contribution made by a[i+1] this time ,, but former is much easier to understand I think

        • »
          »
          »
          »
          »
          9 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          I have understand it.Thank you very much!It's based on the relationship between now and future. I have some thoughts:This method is beautiful! But i think it's not better than the tourial because it use O(n) dp vector while the tourial not use.

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Hey! I had a different idea and wanted to ask if it's close to the correct approach?


      I thought of defining $$$dp[i]$$$ as the total number of decreasing subsequences that end in prefix $$$[1..i]$$$

      Then I figured: if we already know $$$dp[i - 1]$$$, we can add all valid subsequences that include $$$a[i]$$$ and that gives us $$$dp[i]$$$

      So the final answer will be $$$dp[n]$$$

      Example
    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Your answer is very clear, I like it very much.

    • »
      »
      »
      9 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      Such a cool solution, i think if we observe carefully, this solution works with just the condition that elements of the array $$$p$$$ are distinct. [This solution doesn't use the condition that $$$p$$$ is a permutation, it also doesn't use the fact $$$max(p_i, p_{i + 1}) \gt p_{i + 2}$$$, so this solution is more general.

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      in condition pi<pi+1 what you are doing is dp[i] = dp[i+1] +n-(i+1)+1 because in all the sub arrays start with arr[i] thier LDS will start with arr[i+1]? am i correct ?

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      wow

      really clean

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Another solution is thinking it as a tree — https://mirror.codeforces.com/contest/2128/submission/347202769.

      This lets you calculate for each element what is the contribution of it in the answer.

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      is this solution for all types of permutation? is this condition max(pi, pi+1) > pi+2 essential for the dp solution to work?

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    how to prove lds at i+2 must take one of pi pr pi+1 as second last element ? wlog assume pi>pi+2 and pi+1<pi+2 then what if pi-1 has value < pi but also pi-1 >pi+2 will it not be more better to consider second last element be pi-1 instead of pi ?

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      In fact, it's the same. Because in your situation, there must be $$$p_{i-2} \gt p_i$$$. So whether it's for $$$p_i$$$ or $$$p_{i-1}$$$, they are both the second to last element. The impact on the subsequent part is the same.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Hi, just wanted to ask how do we arrive at this condition: dpi=max(dpi−2+(i−2)+(i−(i−2)),dpi−1+(i−1)+(i−(i−1))), what does the (i-2) and (i-(i-2)) signify? Thanks

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      $$$ dp_i $$$ represents the $$$ LDS $$$ ending at the $$$ i-th $$$ index. Now we've two options, either the LDS will have $$$ p_{i-2} $$$ as second last element or $$$ p_{i-1} $$$ as second last element. Let us consider them more generally like this.

      $$$ LDS $$$ has $$$ p_j $$$ as second last element. All the $$$LDS$$$ having $$$ p_j $$$ as last element will have an element $$$ p_i \lt p_j $$$ added at the end, hence their length increases. There are $$$ j $$$ such sequences and all get one increment so we get $$$ j $$$ increments in total. Then, all the elements in the range $$$ (j, i] $$$ will have only themselves as $$$LDS$$$ i.e their length would be 1 so a further $$$ i - j $$$ needs to be added. So more generally, we get:

      $$$ dp_i = dp_j + j + i - j $$$

      which can be translated to both $$$ i - 2 $$$ and $$$ i - 1 $$$. Note that this is just equivalent to

      $$$ dp_i = dp_j + i $$$
  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    awesome

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

WOW NICE TUTORIAL, I AM WAITING FOR RATING CHANEGS

»
10 months ago, hide # |
 
Vote: I like it +32 Vote: I do not like it

The jump between E1 and E2 was huge. But great contest.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I had no clue about B till the very end but got C pretty quicklu. I dont know how so many people got it lol

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +4 Vote: I do not like it

    I found C to be very tricky problem.

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it +4 Vote: I do not like it

      Same C was not trivial for me

      very bad contest performance for me. Got failed systest on A as missed '='. B I just did some shitty logic and C so much time to do it. and D i just couldn't think the logic calmly.

      • »
        »
        »
        »
        10 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        I also got a panic when I read in the comments about = case in A, thankfully I had handled it.. will be big shock for everyone who missed that.

»
10 months ago, hide # |
 
Vote: I like it +20 Vote: I do not like it

Amazing E2. Walking from range of min to range of max is quite a cool trick, never thought I can use this trick from MO in CP :P

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anybody explain the proof for C in simpler terms.

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    for array -> [10,5,6,0,0,0,0.......]

    To be able to construct this array, it must satisfy the condition: Ai≤min⁡(A1,…,Ai−1)×2−1 for all 1<i<=n

    Why is that? Let me explain with the example of the third element (A2=6). The largest value we can achieve for A3 depends on the previous elements. We can add at most 5 in one turn, because adding more than that would affect A1. But we can do better than that by first adding 4, then adding 5 in subsequent turns, which ends up giving us 9 for A3. i think you can understand that now we can make it any elements in range 0 to 2mx-1

  • »
    »
    10 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +5 Vote: I do not like it

    Sorry this is a really informal explanation, I'm a newbie too.

    1. Try an arbitrary number like 40, the max you can build to the right of it is +39 then +40 =79. Try 5, the largest you can build is 4+5=9. For any n to the largest you can go is (n-1) + n. In other words next value < 2*n

    2. Its optimal to build left to right, you cant skip values (aka leave it at 0) if you want to build values to its right.

    3. You have to keep track of the minimum allowed as you go left to right. Say b[0] = 10 the limit is now 19. If b[1] =15 it's fine, because its within the limit. But the limit is still tied to 10*2 -1 =19, the lower value not 15*2 -1 = 29.

    If we were to try to build anything greater than 19 anywhere to the right of b[0], b[0] would have to increase beyond 10 first, as we have proved in point 1 the max it can go is 2*n -1.

»
10 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

very happy to see very less low ranked people in higher ranks.. do we have some new AI protection

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Good contest, however I found C to be on easier side this time

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

is it possible to solve D without the max(pi,p_(i+1))>p_(i+2) condtion?

»
10 months ago, hide # |
 
Vote: I like it -9 Vote: I do not like it

someone might've mentioned, but A is solvable in O(n).

for B, solvable by taking first two, then sorting left and right based on the previous 2 values

the answer for C is a bit confusing, but that might just be me. the solution i found simplest was to keep track of min value and ensure that all after it are strictly less than 2*(min value), which is probably exactly the same as the solution text, but a bit simpler worded for anyone that might be confused like me

  • »
    »
    10 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    How is A solvable in O(n), i don't see it

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      i solved it in nlogn dont know about o(n) tho

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      simple, for each number a[1] to a[n] we go from 1 to 31 (k) and find the first power of two where (1 << k) * a[i] > c. we form a separate array where we keep track of how many numbers there are for each k. once we have this, we can simply go through the array and find out how many of the integers can be used for free. for this, a slight complication is the fact that if there are k's where p[k] = 0, which is why we keep track of how many zeroes there are, because they allow us to use more of the next values. in my code, this is accomplished via a variable called leeway. the total time complexity is O(t * n * 31), or O(n) for each test case, since the 31 is a constant. the code isn't bad so you might be able to clear up anything i've explained badly with it.

          #include <bits/stdc++.h>
          using namespace std;
           
          int main()
          {
          	ios::sync_with_stdio(false);
          	cin.tie(0);
          	cout.tie(0);
          	int t;
          	cin >> t;
          	for(int i = 0; i < t; i++) {
          		int n;
          		long long c;
          		int coins = 0;
          		cin >> n >> c;
          		vector<int> a(31, 0);
          		for(int j = 0; j < n; j++) {
          			long long x;
          			cin >> x;
          			if(x > c) {
          				coins++;
          				continue;
          			}
          			for(int k = 0; k < 31; k++) {
          				if(x * (1 << (k + 1)) > c) {
          					a[k]++;
          					break;
          				}
          			}
          		}
          		int leeway = 1;
          		for(auto i : a) {
          			coins += max(i - leeway, 0);
          			if(leeway >= i) {
          				leeway -= i - 1;
          			}
          			else {
          				leeway = 1;
          			}
          		}
          		cout << coins << '\n';
          	}
          }
      
      • »
        »
        »
        »
        10 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        The time taken for the code to run should be no less than a code with O(n^2) because n <= 30

        • »
          »
          »
          »
          »
          10 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          yeah, for n <= 30. if n went up to 10^9 my code would still run in linear time as opposed to nlogn or n^2 tho

          • »
            »
            »
            »
            »
            »
            10 months ago, hide # ^ |
             
            Vote: I like it 0 Vote: I do not like it

            There's a reason n wasn't bounded at 10^9 , the last element that's getting multiplied would be 2^10^9 , that's some crazy size. 2^30 is ~ 10^9 , that's why it's bounded at 30.

            • »
              »
              »
              »
              »
              »
              »
              9 months ago, hide # ^ |
               
              Vote: I like it 0 Vote: I do not like it

              did you even read my solution? n is the length of the array, there's no reason to use 1 << n.

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    WTH!!!! How is A solvable in O(n)???

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by bestial-42-centroids (previous revision, new revision, compare).

»
10 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

I can't access the solution codes, pls fix this

»
10 months ago, hide # |
 
Vote: I like it -6 Vote: I do not like it

A was diabolical in every terms. whoever created it needs to step down . I left the contest cuz of A thinking of an optimised way

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +20 Vote: I do not like it

    You need to chill out. Why would you need an optimised way when n <= 30

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    well, it exists lol

    looking for faster than required is usually bad practice for competitions but in this case you were onto something. keep it up! that mentality is very good

»
10 months ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

Contest number 999999 to solve a problem using -1, +1 median trick and binary search on answer.

»
10 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

my solution for D is takes somewhat a different approach, i solved D with dp with a couple of key observations:

we first handle the lds problem individually for one singular array a[n], and define dp[i] as the longest lds ending with position i.

observation 1: in standard lds problems, dp[i] is usually computed from multiple previous states dp[j]'s where a[j] > a[i], j < i. however, due to D's unusual constraints, we can prove through contradiction that the only j's that are relevant is i-1 and i-2.

this observation decreases dp's computing time complexity to O(n).

observation 2: we can also prove (again by contradiction) that dp[i] >= dp[j] for all j < i. this brings to an important idea: since lds(1, i) equals to the maximum of dp values from 1 to i, lds(1, i) = dp[i].

now, define f(i) as lds(i, i) + lds(i, i + 1) + ... + lds(i, n). using the observations above, we can calculate f(1) in o(n) time. how can we transition f(i) to f(i + 1) quickly?

we can break it down into two cases:

if a[i] > a[i + 1], then a[i] is the maximum of the array a[i...n], which can lead to the fact that all lds(i, k), i <= k <= n starts with a[i]. so, all lds's are shortened by one, which gives: f(i + 1) = f(i) - (n - i + 1).

on the other hand, if a[i] < a[i + 1] then it can be proven that all lds(i, k), i < k <= n (notice the how its < not <=) does not start with a[i], since with k > i + 2 it it always better to choose a[i + 1] as the starting point rather to a[i]. so in this case, f(i + 1) = f(i) - 1.

now f(n) can be calculated in O(n), summing all f(i) gives the answer.

total time complexity: O(n).

code: link

»
10 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

The contest was fun! Enjoyed during the contest!

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by bestial-42-centroids (previous revision, new revision, compare).

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

why my code failed for submission (problem a), what's wrong in my code ?

code: ~~~~~

include <bits/stdc++.h>

define ll long long

define all(v) v.begin(), v.end()

using namespace std;

bool check_bool(string str){ int i=0,j=str.size()-1 ; while(i<j){ if(str[i]!=str[j]){ return false ; } i++ ; j-- ; } return true ; } bool check_frq(string str){ map<char,int>mp ; for(int i=0;i<str.size();i++){ mp[str[i]]++ ; } bool ptr= true ; for(auto it=mp.begin();it!=mp.end();it++){ if(it->second%2==0){ continue ; } else { if(ptr==true){ { ptr=false ; continue ;}

}else{
        return false ;
       }
  }

} return true ; } long long gcd(long long a,long long b) { while(b) { long long t=a%b; a=b; b=t; } return a; } ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); } int main() { int t=1; cin>>t ;

while(t--){
  int n ;
  ll c;
  cin>>n>>c ;
  vector<ll>vi(n) ;
  for(int i=0;i<n;i++){
     cin>>vi[i] ;
  }
  sort(vi.begin(),vi.end()) ;
  int ans=0 ;
  int j=-1 ;
  for(int i=n-1;i>=0;i--){
     if(vi[i]<c)
     {
        j=i ;
        break ;
     }
  }
  int ptr=0 ;
  for(int i=j;i>=0;i--){
     ll x=ptr*vi[i]*(ll)2 ;
     if(x<c){
        ptr++ ;
        ans++ ;
     }
  }
  cout<<n-ans<<endl ;
 }
return 0;

} ~~~~~

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Guys, how to notice facts like hint1 in D? Let bi=max(ai,ai+1), show that b1≥b2≥…≥bn−1.

I mean to say, how do I know what to look for?

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    I have no idea. I feel like editorials do a bad job of capturing thought process. They focus more on proving a solution to be correct than showing people HOW to come up with a solution.

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    Sorry, I don't really recall how I solved this problem but I can try an explanation.

    Perhaps a first remark you could do is that if the condition was that if a[i] >= a[i+1] for every i, then the array would be decreasing and LDS would be the whole sequence.

    So in a sense, max(a[i], a[i+1]) >= a[i+2] feels like that the array is "almost decreasing". Now to leverage that, you should get a feel of what "almost decreasing" means, in particular how much it prevents you from increasing. For that it can be helpful to try to generate arrays that respect the condition, and try to "feel the ceiling".

    Suppose you start with [50, 30, 40], now after the 40 you see that you must put something less than 40. Let's say you put 39, then after that you still must put something less than 40. You start to feel the ceiling. You wonder if you can increase back to something above 40, but you will quickly realize that's impossible, and that's what will make you realize that a[i] < a[i+1] implies a[i+1] > max(a[i+2], ..., a[n]), which is the hint2 (the hint1 is only useful to prove hint2).

»
10 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Nice contest :D

Alternate solution for D:

Let dp[i] be the sum of all the subarrays that ends with the index i.

Set dp[0] = 1. Then, for 1 <= i < n, we have dp[i] = dp[i-1] + (i+1) if p[i] < p[i-1], and dp[i] = dp[i-1] + 1 otherwise. The answer is the sum of all the dp[i]s.

»
10 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Why this solution isn't working for problem E1??

What's the reason?

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    You cannot assume that the largest median can only be found in an interval of size k (like your solution calculates). In other words, it may be the case that the largest submedian can be found in an interval size >k.

    • »
      »
      »
      10 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      I calculate for interval of size k and k+1 (One even and odd length interval). I thought all other interval of size >= k+2 can be convert to these two cases.

      Edit: Now, I got it. One of case where my solution fails is:
      9 6
      1 6 6 1 3 3 4 8 8

      Expected Output: 6
      My Output: 4

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Great contest, thanks :)

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

ai<x≤min(a1,…,ai−1)≤min(b1,…,bi−1).

Hence, bi=ai+x≤2x−1≤2mi−1.

Can any one help me with how final equation came from it previous step. That is how min(a1,...,ai-1)==2x-1?

»
10 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it
»
10 months ago, hide # |
 
Vote: I like it -10 Vote: I do not like it

F was literally useless in this contest. Nice contest overall !

»
10 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

These problems are such that you're just better off guessing something rather than trying to prove a solution. Don't make such problems please.

»
10 months ago, hide # |
 
Vote: I like it +18 Vote: I do not like it

I really enjoyed E2 and it's a very cool problem. But I think making E1 worth 1750 (same as E2) was too much. It is really demotivating to see my score on E2 being less than my score on B.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Any idea about the rating of B & C?

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I can solve E1 very fast because it was same as this problem

https://mirror.codeforces.com/problemset/problem/1486/D

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone please explain to me why my code for problem C isnt right?

The code in contest:

Code

The code after the contest (after i change a little bit to make it like the tutorial):

Code

But both are wrong, however.

Can someone please explain to me?

(I put both in void solve() btw)

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I know the reason

    You return the function solve() before reading all the array a because of this problem is multi test case

    if the array have 10 numbers and when you read the 5th number, you found it is incorrect and you return the function. It means that there is still 5 numbers you don't read

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Check my solution on D 331161296

»
10 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

I also have a dp solution for D.

Let $$$dp_i$$$ be the sum of LDSs of the segment $$$[i, j]$$$ with $$$i \leq j \lt n$$$ and $$$dp_i = 0$$$ with all $$$i \gt n$$$ and $$$LDS(i, j)$$$ be the LDS for the subarray $$$a_i, a_{i + 1}, ... a_j$$$

Due to the fact that $$$max(p_i, p_{i + 1}) \gt p_{i + 2}$$$, I claim (with no solid proof) that $$$LDS(i, j) = LDS(i + 2, j) + LDS(i, i + 2) - 1$$$ with $$$j \geq i + 2$$$

First, initialize $$$dp_n = 1$$$

Then consider $$$i \lt n$$$

We have 3 cases:

Consider the segment $$$[i, i]$$$. Clearly the LDS is 1. So first $$$dp_i = 1$$$

Then consider the segment $$$[i, i + 1]$$$. The LDS is 2 if $$$a_i \gt a_{i + 1}$$$ and 1 otherwise. So the contribution to $$$dp_i$$$ is either 2 or 1.

Next consider the remaining segments. According to the claim above, $$$LDS(i, j) = LDS(i + 2, j) + LDS(i, i + 2) - 1$$$ with $$$j \geq i + 2$$$. Since $$$LDS(i, i + 2)$$$ is a constant, and we have $$$n - i - 1$$$ subarrays starting from $$$i + 2$$$, we can deduce that the sum of the LDS in this case is $$$(n - i - 1)*[LDS(i, i + 2) - 1] + dp_{i + 2}$$$.

Therefore, my dp formula is as follows:

$$$dp_n = 1$$$

$$$dp_{n - 1} = 1 + LDS(i, i + 1)$$$

$$$dp_i = 1 + LDS(i, i + 1) + [LDS(i, i + 2) - 1]*(n - i - 1) + dp_{i + 2}$$$

Then sum all of the dp values to get the answer.

This runs in $$$O(n)$$$ time

Submission: 331179927

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I do not understand how problems like E1 are allowed in Div2 style contests. E2 alone should have been enough.

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    I agree, because there was a problem same as E1 was in contest.

    Because I done it so I can clear the E1 very fast :D

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

not my dumb ahhh failed system test on A

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

submission link

Can someone please explain why my O(n^2) solution for C passes?

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I don't think B is even a real problem‌.Actually,no matter how you write your program,it'll can be accepted.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I have a quite stupid solution for $$$C$$$

Iterate from $$$2$$$ to $$$n$$$, let the current number be $$$x_i$$$ and $$$mn$$$ be the minimum of all elements before it.

Also, let $$$l$$$ be $$$floor(\frac{x_i - 1}{2})$$$ and $$$r$$$ be $$$x_i - l$$$

Iff $$$max(l, r) \gt mn$$$ then the answer is definitely "NO" and otherwise.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

After carefully studying your solution section, I feel that there might be a typo in the "It's optimal" part. If ai < a{i+1}, then a{i+1} must be greater than a{i+2}; otherwise, max(ai, a{i+1}) = a{i+1} cannot be greater than a{i+2}.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone suggest some problem that involves considering all possible subarrays, like problem D?

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I can't understand problem C at all.... can anyone help?

»
10 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

In prb D edi, shouldn't it be "if ai < ai+1 we cannot have ai+2 > ai+1" ?

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I really appreciate problem E2, but I think this test should really have been considered. It's one of the easiest mistakes one can make while sweeping that they set answers for the whole $$$[min, max]$$$ range every time, instead of updating only the answers that are yet to be found.

The hack test $$$n=300\,000$$$, $$$k=2$$$, $$$[1,n-1,2,n-1,2,n-1,...,2,n-1,2,n]$$$ forces the minimum and maximum median to be at the very ends, and every range of even length (except for the very ends) to have $$$[2,n-1]$$$ as the median range. Thus, sweeping is performed for $$$\mathcal{O}(n)$$$ iterations and every second iteration it updates $$$\mathcal{O}(n)$$$ answers, leading to $$$\mathcal{O}(n^2)$$$ time in total.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

D was an excellent problem and C was easy compare to other div-2 contest

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

E1 is such a good problem if it was provided in a div3 round, or an edu round.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i have a idea for problem D. We just need to notice that the sequence is a decreasing one. However, there may be some positions where it increases once. It is absolutely impossible for three numbers to be in increasing order. Therefore, it is easy to figure out the subsequent operations by drawing a diagram.

#include<iostream>
#include<vector>
#define int long long
using namespace std;
signed main()
{
    int t; cin >> t;
    for (int q = 0; q < t; q++)
    {
        int n; cin >> n; vector<int> v(n + 1, 0);
        for (int i = 1; i <= n; i++) cin >> v[i];
        int sum = 0;
        for (int i = 1; i <= n; i++)
        {
            sum += (i * (n - i + 1));
        }
        int tar = 0;
        for (int i = 2; i <= n; i++)
        {
            if (v[i] > v[i - 1]) tar += ((i - 1) * (n - i + 1));
        }
        cout << sum - tar << endl;
    }
    return 0;
}
»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i spent long on A~E1, i didn't solve E2 in the test. But that's really a good problem :)

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

What a tricky E1, but I like it.

»
9 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

There is a solution to problem D that does not need the statement max(p_i, p_{i+1}) > p_{i+2} to be true, and it does not have to a be permutation either meaning it will work for any array.

Ideas is to calculate for each index i where 0<=i<n, if r = i, what would the answer be and sum of them is the final answer. To calculate it we use idea of Longest Increasing Subsequence in O(n log n), but it is Longest Decreasing Subsequence now.

Overall time complexity is O(n log n).

Link to the submission: https://mirror.codeforces.com/contest/2128/submission/331402684

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

It appears that the dp approach for problem D is more intuitive to implement, when you try to figure out the relation with a paper.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

A was very hard

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    E1 was very easy

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Never mess up with M_Abu_Bakr_Shahid He is my brother

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        bro you both are the same person, you are acting as if I don't know how to read names, LOL! The stupidity of this decision that you made is so funny!

        • »
          »
          »
          »
          »
          9 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          So why did you hurt me by writing an Afghanistan-Pakistan message

          • »
            »
            »
            »
            »
            »
            9 months ago, hide # ^ |
            Rev. 2  
            Vote: I like it 0 Vote: I do not like it

            Bro I didn't know that you were such a cry baby, my bad darling!

            • »
              »
              »
              »
              »
              »
              »
              9 months ago, hide # ^ |
               
              Vote: I like it 0 Vote: I do not like it

              I am currently sitting next to him watching him doing all this stuff

            • »
              »
              »
              »
              »
              »
              »
              9 months ago, hide # ^ |
               
              Vote: I like it 0 Vote: I do not like it

              Some hacker posted bad blogs and I recieved this message Hello, ss250403222_M_Abu_Bakr! Your recent comments/blog posts/other activities have violated rules of our community. It seems this content is nonsensical, troll-like, dirty, coarse, offensive, aggressive, meaningless, violating other rules or ethical norms. Probably, it wasn’t written in English (or Russian if you specify this language for blog post or comment). Please, be polite, reasoned, do not publish junk content, do not violate conventional ethical standards. You should not publish content that does not correspond to the topic of discussion or does not correspond to the topic of the website. Use common sense when analyzing to write or not write any content. You should not publish comic content, especially if it is not interesting to a wide part of the audience, repeats the existing one, or has no connection with competitive programming. Your account has been blocked to write any social content for 48 hours and your recent content has been deleted. Hope you follow the relevant conclusions and this situation will not happen again. In case of repeated violations, more severe penalties may be applied to your account, up to and including blocking.

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        I guess mabubakrshahid2 is also your brother.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This is my solution to problem D. First, consider the sum of the LDS of sub-segments starting with 1. Let f_i be the contribution of sub-segment [1,i].

Since $$$\max(p_i, p_{i+1}) \gt p_{i+2}$$$, transferring from $$$i$$$ and $$$i+1$$$ to $$$i+2$$$ must be non-degenerate.

Next, consider how to transfer from the sum of $$$\text{LDS}$$$ starting with $$$i-1$$$ to the sum of $$$\text{LDS}$$$ starting with $$$i$$$. Let $$$g_i$$$ be the sum of $$$\text{LDS}$$$ starting with $$$i$$$, and initialize $$$g_1=\sum \limits_{i=1}^n f_i$$$.

If $$$a_{i-1} \gt a_i$$$, then for all sub-segments, the transition from $$$i-1$$$ to $$$i$$$ is lost, so $$$g_i=g_{i-1}-(n-i+1)-1$$$. The final subtraction of 1 represents the contribution from the segment $$$[i-1,i-1]$$$, and the same applies below.

Otherwise, there is no loss, and $$$g_i = g_{i-1} + 1$$$.

The answer is $$$\sum \limits_{i=1}^n g_i$$$.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I am unable to view code. Kindly help me out

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Dear Codeforces Team,

I am Ankit.Kushwaha, and I recently received a plagiarism warning for problem 2128C from Codeforces Round 1039 (Div. 2), associated with solution ID: 331146482. I respectfully wish to clarify that the submitted solution was written entirely by me, independently, during the contest using Visual Studio Code on my personal machine, without any external assistance or reference.

The approach I implemented involves maintaining the current minimum of the array while verifying that each subsequent element satisfies the condition arr[i] ≤ 2 * currentMin - 1, with a special check in case the minimum is zero. Given the simplicity and deterministic nature of the logic, it is highly likely that multiple participants may have arrived at similar implementations independently.

At no point did I upload or share my solution on any public platforms, nor did I utilize online IDEs such as Ideone or any other tools that could inadvertently expose my code.

I sincerely request a re-evaluation of my case. If any further information or clarification is required, I would be glad to provide it. Thank you for your time and consideration.

Sincerely,
Ankit.Kushwaha

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

E2 was nothing short of brilliant.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Nevertheless, I wouldn't have been able to solve it without the hint from E1

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I personally find the editorial for D rather difficult to follow, and I want to suggest some changes.

There should be an assertion that $$$a_i = 0$$$ for all $$$i \gt n$$$.

The sequence $$$(i_1, ..., i_m)$$$ is not an LDS. $$$(a_{i_1}, ..., a_{i_m})$$$ is.

The optimality proof of the LDS is kind of hard to follow, and there's also a typo.

The statement "if $$$a_i \lt a_{i+1}$$$ we cannot have $$$a_{i+2} \lt a_{i+1}$$$" is wrong. It should be corrected to say: "if $$$a_i \lt a_{i+1}$$$ we must have $$$a_{i+2} \lt a_{i+1}$$$".

Here's my interpretation of the optimality proof. Please correct me if I'm mistaken or it can be improved.

Let $$$I$$$ be the index sequence $$$(i_1, ..., i_m)$$$ from earlier, and $$$E$$$ be the index sequence of any LDS of $$$a$$$. Let $$$i$$$ be an arbitrary integer in $$$[1, n]$$$, and consider the following.

  • If $$$a_i \gt a_{i+1}$$$, then $$$i \in I$$$ by definition. For $$$E$$$, $$$i$$$ may or may not exist.
  • If $$$a_i \lt a_{i+1}$$$, then $$$i \notin I$$$, but $$$i+1 \in I$$$ (because of the condition $$$\max(a_i, a_{i+1}) \gt a_{i+2})$$$. For $$$E$$$, at most one element in $$$(i, i+1)$$$ can exist.

In both cases, $$$I$$$ always takes at least the number of elements from $$$E$$$, so $$$|I| \geq |E|$$$.

I know these are subtle changes, but I think they can help clarify some points of the editorial.

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I think the editorial for F is incomplete (and I arrived at the solution with this exact incomplete reasoning lol). You don't really show that the condition $$$d_L(u, v) \lt d_R(u, k) + d_R(k, v)$$$ holding for all $$$u, v \in P$$$ suffices for any path $$$P$$$ (you show this for some shortest path $$$P$$$, and make use of properties of shortest paths), which is required as our Djikstra's-like algorithm later isn't really being forced to only consider shortest paths.

  • »
    »
    3 months ago, hide # ^ |
    Rev. 5  
    Vote: I like it 0 Vote: I do not like it

    The necessary part incorrectly assumed that $$$P$$$ was shortest in $$$w_P$$$, my bad. But we can make things work as follows.

    TLDR: instead of looking at $$$d_L(u, v)$$$, look at the length of the subpath of $$$P$$$ going from $$$u$$$ to $$$v$$$.

    Let $$$P$$$ a path from $$$1$$$ to $$$n$$$. For every $$$u \in P$$$, let $$$\delta_u$$$ the sum of $$$l$$$-weights of the edges of $$$P$$$ that leads from $$$1$$$ to $$$u$$$. In particular $$$\delta_1 = 0$$$ and $$$\delta_n$$$ is the length of $$$P$$$. As you pointed out, $$$\delta_u$$$ might be larger than $$$d_L(1, u)$$$.

    Let's say that $$$P$$$ avoids $$$k$$$ if $$$|\delta_u - \delta_v| \lt d_R(u, k) + d_R(k, v)$$$ for all $$$u, v \in P$$$. This is different from what I said in hint 2.

    Let $$$w_P(e) = l(e)$$$ if $$$e \in P$$$ and $$$r(e)$$$ otherwise, and $$$G_P$$$ the corresponding weighted graph.

    Claim 1: if there is a valid assignment $$$w$$$ of weights, then there exists a path $$$P$$$ that avoids $$$k$$$.

    Proof

    Claim 2: if a path $$$P$$$ avoids $$$k$$$, then $$$w_P$$$ is valid (even if $$$P$$$ is not a shortest path in $$$G_P$$$).

    Proof

    Dijkstra algorithm either

    • finds a path $$$P$$$ that avoids $$$k$$$ (that may or may not be shortest in $$$G_P$$$), in which case by claim 2, the answer is YES.
    • tells us there is no path $$$P$$$ that avoids $$$k$$$, in which case by claim 1, the answer is NO.
»
2 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In d solution you mean "if ai<ai+1 we cannot have ai+1<ai+2" Instead of "if ai<ai+1 we cannot have ai+2<ai+1" right?