BledDest's blog

By BledDest, 11 months ago, translation, In English

2112A - Race

Idea: BledDest

Tutorial
Solution (Neon)

2112B - Shrinking Array

Idea: BledDest

Tutorial
Solution (adedalic)

2112C - Coloring Game

Idea: BledDest

Tutorial
Solution (Neon)

2112D - Reachability and Tree

Idea: adedalic

Tutorial
Solution (adedalic)

2112E - Tree Colorings

Idea: BledDest

Tutorial
Solution in M sqrt M (Neon)
Solution in M log M (BledDest)

2112F - Variables and Operations

Idea: BledDest

Tutorial
Solution (BledDest)
  • Vote: I like it
  • +152
  • Vote: I do not like it

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

Tutorial for F shows the one for A.

Very nice contest, thanks!

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

I guess by mistake you have put the editorial of A in F ;-;

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

rating changes?

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

when we get our rating?

»
11 months ago, hide # |
Rev. 3  
Vote: I like it +36 Vote: I do not like it

I have another interesting solution for E since I couldn't come up with that dp idea. My solution brute forces and generates all the possible answers for n (vertices count) and doing this for all n <= 24 seems enough and if you can implement it carefully it will pass the time limit. Code.

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

did anyone else not have his rating change, because I did and when I checked it said that it was unrated for me but I am under 2100 and I participated as rated

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

The problems are very nice, especially for B,E and F :)

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

325787868 what was wrong with my logic?

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

Thank you for a wonderful contest, D was beautiful. I was wondering how to count number of good pairs given a directed tree as in D

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

    I think this works :

    Given the directed tree, you can count for each node, the number of in-edges (to the node) times the number of out-edges (from the node). Summing it altogether gives the number of paths of length 2.

    And if it's equal to 1, then it works, else it doesn't work.

    Proof : If it's equal to 1, then there cannot exist a path of length >= 3, because for example if you have a->b->c->d, then you have clearly more than 2 paths of length 2 (a->b->c, b->c->d). So there is exactly one path of length >= 2, so it works. And if not, it clearly doesn't work.

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

      Thank you for this. I am sorry I was not clear but my query was regarding any type of directed tree. Is there an efficient way of counting number of good pairs.

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

        I have thought about it, and I think this works :

        You do a DP on the tree (you can root it in any way).

        For each node, you look at its subtree and you try to calculate the following three values :

        • $$$end[node]$$$ -> number of paths that end at the node;

        • $$$start[node]$$$ -> number of paths that start at the node;

        • $$$tot[node]$$$ -> the total number of paths;

        Now, you can calculate these values recursively :

        Suppose you need to calculate the three values of a node $$$r$$$, and you already know the values for his $$$k$$$ children.

        Separate these children into two categories :

        • $$$a_1, a_2, \ldots, a_n$$$ such that there is an oriented edge from $$$a_i$$$ to $$$r$$$;
        • $$$b_1, b_2, \ldots, b_m$$$ such that there is an oriented edge from $$$r$$$ to $$$b_i$$$.

        Then,

        $$$\boxed{end[r] = \sum_{i=1}^n (end[a_i] + 1)}$$$
        $$$\boxed{start[r] = \sum_{i=1}^m (start[b_i] + 1)}$$$

        For $$$tot[r]$$$, you should count all the $$$tot[a_i]$$$ and $$$tot[b_i]$$$ and $$$end[r]$$$ and $$$start[r]$$$, and you should count all paths that originate from a subtree of $$$a_i$$$ to a subtree of $$$b_i$$$.

        This gives

        $$$\sum_{i=1}^n \sum_{j=1}^m (end[a_i] + 1)(start[b_j] + 1) = (\sum_{i=1}^n (end[a_i] + 1)) (\sum_{j=1}^m (start[b_j] + 1)) $$$

        Finally you have

        $$$\boxed{tot[r] = \sum_{i=1}^n tot[a_i] + \sum_{j=1}^m tot[b_j] + end[r] + start[r] + (\sum_{i=1}^n (end[a_i] + 1)) (\sum_{j=1}^m (start[b_j] + 1))}$$$

        Hopefully it works, and my complexity is $$$O(n)$$$ !

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

          Can you describe what are you trying to calculate exactly? Because if you're counting the number of paths then it's just $$$\sum_{v}{start[v]}$$$ because every path has a starting vertex.

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

            When I say $$$start[v]$$$, $$$end[v]$$$, $$$tot[v]$$$, I only consider the number of paths in the subtree of $$$v$$$, not in the whole tree !

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

              Why not to calculate $$$start[v]$$$ as the number of paths in the whole tree starting at $$$v$$$?

              You can just calculate $$$start(v) = \sum\limits_{v \to to}{(1 + start(to))}$$$ recursively without any problems since there are no cycles in the graphs.

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

                This is smart; I wasn't smart enough to find this short smart idea ...

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

      Can someone help me debug the solution for D problem

      My Approach is to first assign the direction layer by layer using BFS. If one layer has upward direction of edges then the next layer would have downward direction and so on. this would ensure we have exactly (n — 1) pairs reachable.

      Next after this i am finding out the node having degree 2 and has one of the child as leaf node and then reverse its direction to make the 2 length path.

      Submission Link :- https://mirror.codeforces.com/contest/2112/submission/326094031

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

        You only need a single condition that if a node exists with degree 2, then simply mark it as the root, then assign edges separately for left and right using BFS/dfs. this left -> root and root ->right will give 3 pairs, and the rest pairs by that alternate assigning of edges

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

        your code fails for this kind of cases it says "NO" but its possible, see the image for the edges

        TestCase :- 
        1
        9
        4 1
        4 2
        4 3
        4 5
        6 5
        6 7
        6 8
        6 9  
        

        Screenshot-2025-06-27-022112

  • »
    »
    11 months ago, hide # ^ |
     
    Vote: I like it +4 Vote: I do not like it
    My code
»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Forgot to use long long… lesson learned.

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

I wonder how to use two pointers to improve the time complexity of $$$C$$$ to $$$O(n$$$$$$2$$$$$$).$$$

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

32595261 Hey can anyone tell why this is failing. I modify the for loop to seperate the logic to check for 2 consecutive elements and 3 consecutive elements and it starts working. I wanted an example testcase for which this code wont work. Thanks!

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

Very good contest, thanks.

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

Has this contest become unrated?

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

When the rates update

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

Edi not linked on contest page

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

So when will rating update?

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

Will the ratings not get updated.

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

Does anyone could say something about rating changes? If it's been a problem or it's in process, etc. We would like to know something please

»
11 months ago, hide # |
 
Vote: I like it -7 Vote: I do not like it
// Problem in the rating system
bool problem = false;
cin >> problem;
if (problem)
{
    cout << "Please tell us the type of the problem:" << endl;
    string x;
    cin >> x;
    if (x == "cheaters")
    {
        cout << "Post their names on the blog and block them from the website." << endl;
    }
    else if (x == "It becomes unrated")
    {
        cout << "Why? Please give us some reasons!" << endl;
    }
    else // It will be posted, but there are technical problems
    {
        cout << "Okay, you should have told us, but it's fine. I'm waiting — please give us a deadline." << endl;
    }
}else
{
cout << "No there is a problem, I am sure check it again" << endl;
}

// please don't hack the code
»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

325760640

I tried this approch in problem A and it works

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

Can someone explain me this part better for E?

Note that if a vertex is not green, its entire subtree must be colored the same color: for example, if the vertex is blue and it has a green or yellow descendant, the root is unreachable from that descendant without passing through that blue vertex. At the same time, the green vertices do not impose any additional constraints.

why is this tree illegal? (green)-(blue)-(green)

This is also the third example of the pretest 1, but I don't understand why this coloring has to be excluded

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

    just understood this, both green and yellow are reachable without blue means green-green, yellow-yellow and yellow-green

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

    I have the same issue... Why it is not considering that case??

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

      If we satisfied second condition with (green)-(blue)-(green), then third condition does not works... Because "all yellow and green vertices" should be reachable from each other without blue vertices. it's not (green)-(green) or (green)-(yellow)-(green).

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

Can anyone explain why we need to add dp[x-2] i.e. dp[m] = dp[m/x] + dp[x-2] in E.

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

    dp[x] means number of vertices needed to form x colorings now we are dealing in subtrees so there are 2 more options of coloring them entirely blue or yellow which don't exist in dp[x] so if we find the number of vertices which can be colored in x-2 ways we can do the other two colorings and get x

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

when will rating change

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

is rating updated for educational round div 2

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

Cana anybody tell that why this is not working for problem C

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    int t;
    cin >> t;
    while (t--)
    {
        ll n,ans=0;
        cin >> n;
        ll a[n];
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        sort(a,a+n);
        for (int i = 0; i < n; i++)
        {
            for (int j = i+1; j < n; j++)
            {
                auto it=lower_bound(a,a+n,a[i]+a[j]);
                if (it==a+n)
                {
                    ans+=(n-1-j);
                }
                else{
                    int index=it-a;
                    index--;
                    if (index>j && a[i]+a[j]+a[index]>a[n-1])
                    {
                        ans+=(index-j);
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

This is my submission id , it is giving error in test case 1 of example 3
https://mirror.codeforces.com/contest/2112/submission/326045388

I would be grateful if anyone help me with these
  • »
    »
    11 months ago, hide # ^ |
    Rev. 5  
    Vote: I like it 0 Vote: I do not like it

    I think from what I can tell you have not considered the case when the sum of the three elements chosen by Alice is less than the max element which can be chosen by Bob. For example if you have an input of the form below it will fail because Bob will just color the biggest element blue :(

    1

    5

    1 1 1 2 5

    For the above test case your code says 1 but the actual answer is 0 since Bob can always choose 5 to color blue and win regardless of Alice's choice.

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

      Nvm I realized my counter example actually works for your case my bad idk what went wrong.

      Edit: if (index>j && a[i]+a[j]+a[index]>a[n-1]) { ans+=(index-j); }

      This does not work because a[i]+a[j]+a[index]>a[n-1] is not necessarily true for the indexes which are between j and index that you add to the ans variable. For example with the list 27 32 35 37 45 96, When you consider i=0, j=1 you get that a[0]+a[1]+a[4]>a5 and you consider (0,1,2), (0,1,3), (0,1,4) all as valid options while only (0,1,4) index triplet works.

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

      my code is giving 0 only , could you pls check it once again

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

    you are checking if a[i] + a[j] > a[index], But it is possible for some indexes that this condition holds for index<n-1 but a[i]+a[j]+a[index] <= a[n-1].

    Consider this test case :

    6
    17 20 25 29 30 65
    

    suppose i = 0 (a[i] = 17) and j = 1 (a[j] = 20) then according to your code index = 4 and it is also satisfying index>j and a[i]+a[j]+a[index]>a[n-1] and you are adding (index-j = 3) to your ans or possible index for i = 0, j = 1 are 2,3,4 but index 2 will not work as a[0]+a[1]+a[2] = 62 < a[n-1] = 65

    correct approach :

    calculate index2 < n-1 for which all k such that index2 <= k < n will satisfy a[i]+a[j]+a[k]>a[n-1]

    Use upper bound for calculating this.

    in for loop change the ranges i = 0 to n-3 and j = i+1 to n-2 , with slight changes in your code here is the accepted version :

    Accepted Solution
»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Thanks for the editorial

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

In D I have a doubt!!!!!, I have No; in test 2 case 1507 (hidden case), the thing is as per editorial, the only sufficient condition for n good pairs is to have a vertex with 2 components, but I think we need a vertex with 2 components and one of those component should be 1 degree (connected to only 1 component). I am checking that and if not found output 1.

Because as per my logic, if lets say I have a component of 2 degrees connected to each other, no matter what dirc I change, I will always create more paths than n. So I don't know why.

Can someone give me a test case where this is true!!!!!

My code for ref, if needed here

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

Have you checked MOSS yet?

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

Drop the ratings please :)

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

Hello Codeforces Team,

I have received a message that my solution for problem 2112B (#325782053)coincides with many others. I want to clarify that I wrote my code entirely by myself and did not copy it from any source, nor did I share it with anyone.

I used VS Code, and I didn’t post or share my solution publicly. If the coincidence happened due to unintentional exposure (like online IDE visibility or similar logic), I sincerely apologize and assure you that I’ll be more careful in future contests.

Please reconsider the decision if possible, or let me know if there’s anything I can do to provide more details.

Thank you. tanwarbrijessh

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

I am absolutely stunned by problem E and its solution

A very beautiful problem indeed.

Does anyone have more problems that uses similar arguments?

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

I got the following message :

"Attention!

Your solution 325720028 for the problem 2112B significantly coincides with solutions LuzZ_ShayanZ/325720028, khanna_dhruv/325731757. Such a coincidence is a clear rules violation. Note that unintentional leakage is also a violation. For example, do not use ideone.com with the default settings (public access to your code). If you have conclusive evidence that a coincidence has occurred due to the use of a common source published before the competition, write a comment to post about the round with all the details. More information can be found at http://mirror.codeforces.com/blog/entry/8790. Such violation of the rules may be the reason for blocking your account or other penalties. In case of repeated violations, your account may be blocked."

I would like to clarify that I did not engage in any form of cheating or code sharing during the contest. I wrote my solution independently using VS Code on my personal computer, without using any online IDEs or shared environments. The problem was quite straightforward and naturally leads to a limited set of logical steps — such as checking adjacent differences and detecting local extrema — which explains the similarity in approach.

All my problems A to D are skipped. This was a big bump in my rating so please help me or guide me what to do.

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

Does dp[m/x] + dp[x-2] imply that no subtree has more than 2 children? I understand why we can use dp[x-2], but doesn’t dp[m/x] represent the minimum vertices in a single tree with that many colorings? Why can’t the optimal tree have many children whose coloring product equals m/x? Does dp[m/x] work in this case? Edit: never mind, I believe it is because dp[x-2] accounts for the last subtree and dp[m/x] accounts for the root + remaining subtrees. Please correct me if I am wrong.

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

Nice problems, thanks!

I want to share a bit different approach on problem E.

  1. Let's say that C(T) is number of ways to color tree T.
  2. Let's say that Cs(n) is set of all C(T) among trees T with exactly n vertices.

Let's find Cs(n) for all n's that can be the answer. It can be calculated using dynamic programming like this:

const int MAXM = 500000; // the maximum value of `m` from the statement

// k is size of the first subtree of root
for (int k = 1; k < n; k++) {
    // iterate over the number of colorings of tree without the first subtree
    for (int x : Cs[n - k]) {
        // iterate over the number of colorings of the first subtree
        for (int y : Cs[k]) {
            // add two colorings: all-yellow and all-blue
            y += 2;
            // we don't need too large numbers of colorings
            if (static_cast<long long>(x) * y <= MAXM) {
                Cs[n].insert(x * y);
            }
        }
    }
}

And then if you print the sizes of Cs[n], then you can notice that it stops growing after n = 25. So you don't need to iterate for more than that. Then you can simply find the smallest n for any number of colorings.

I don't know the complexity of this solution, but it is fast enough to pass the testcases with 546 ms. The submission can be found here: 326206231.

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

Some observations for problem E:

m must be a an odd number. why?

Let cnt(v) denote the no. of colorings of the root v of a subtree given that it is green.

If it’s children are u1,u2,…,uk then they have cnt(ui) + 2 total colourings. +2 for all blue and all yellow cases.

Since all subtrees are independent, cnt(v) = (cnt(u1)+2)(cnt(u2)+2)…(cnt(uk)+2)

Consider the base case of a leaf node, it has 3 possible colorings(i.e. odd).

and any answer that is formed from these base cases is a product of odd numbers which is also odd. So, m must be odd.

If m is a power of 3 then the tree with smallest number of nodes is the tree with a root attached to n leaves where n is the power of 3, so n+1 in total.

Using a linear chain we can create all odd number of colorings starting from 1. //Edit : please consider the following to be void for now.

For any given m, find it’s prime factorisation and write it such that the product shows all factors distinctly. E.g. 75 = 5*5*3.(not 5^2*3)

Then the optimal tree is the root connected to n linear chains whose no. of possible colorings are equal to the prime factors(we can have any prime no. using a chain). where n is the total no. of prime factors, considering recurring equal factors to be distinct.

You can simply determine the no. of nodes in each children chain and form the total answer. I guess the dp solution achieves this in an easier way.

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

    Can you please briefly explain how to calculate the number of nodes in each child chain and how it contributes to the final answer?

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

      For a chain of length n, it has 2n-1 colourings. If component chains are of length n1,n2,n3...nk Then for the final tree ans is m =(2n1+1)(2n2+1)...(2nk+1). I have written 2ni+1 instead of 2ni-1 because the 2 cases of all blue and all yellow for component chains are added too.

      Please up-vote.

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

        So, according to you if m itself is a prime number then the optimal tree will be the root connected to 1 linear chain and the number of total nodes in that tree will be (m / 2). Correct me if i'm wrong.

        If that's what you are saying then i guess you are wrong. Cause for m = 11, the ans is 4 not (m / 2). And the tree will be {(1,2), (2,3), (2,4)} which is not a linear chain in my knowledge.

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

          Yes, I guess there is some error in the reasoning. I'll think about it but it seems close.

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

    Your guess about the tree being a bunch of linear chains connected to the root isn't correct. You can see this with m = 11, 13, 17, or 29. This is because as soon as you have a tree that isnt a chain (like with m=9) you can construct trees by attaching those non-chain trees to a common root. For example with m=29, you use the optimal tree for m=27 but with an extra node above the root

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

hello biru

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

I am still not able to understand C solution. I got it that lower bound is to figure out the range, but not the particular conditions!. Can someone explain me? Stuck for four days!

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

for shrinking array B Question

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

For problem E, I'm confused on the line of the editorial "if a vertex is not green, its entire subtree must be colored the same color". If I am coloring a tree with only green and blue (i.e., not coloring any node yellow so there are no yellow-green paths), can't I have green nodes in the subtree of a blue node?

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

    Ah never mind, after seeing the clarification and re-reading the problem statement, I realize that all green nodes must be reachable from each other without passing through blue nodes from the third condition.

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

E is such a good problem

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

Can anyone help me to clear the doubt for tutorial A? Suppose a,x,y=1,2,3 then is there any position for Bob to get the prize always? Even though he chooses 4 as position he will never be able to get the prize at x=2 because a is at 1. The questions asks for a guaranteed position for Bob not that position where he may win conditionally. I may be wrong can anyone help me with this?

Shouldn't the correct condition should be: ~~~~~ int dist = min(abs(a — x), abs(a — y)); int side = (x — a) * (y — a); if (dist > 1 && side > 0) cout << "YES" << endl; else cout << "NO" << endl; ~~~~~ At least a distance of 1 so,that Bob can take that position as Alice and Bob cannot be at same position.

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

Hi, I am currently practicing the problems in this contest & I seem to have gotten stuck on problem D. I have implemented the solution in Python based on the approach in the editorial.

https://mirror.codeforces.com/contest/2112/submission/327620250

However, I keep getting runtime error on the 9th test case, & it beats me as to what the issue might be. Would be lovely if I could get some pointers on this one.

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

Problem D seemed almost to be a copy of a previous problem https://mirror.codeforces.com/problemset/problem/1144/F but anyway Thanks for contest !

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

I suggest to improve the description of the problem F. 'The variable $$$a_{x_i}$$$ gets assigned' or 'The $$$x_i$$$-th variable gets assigned' not 'the variable $$$x_i$$$ gets assigned'. BledDest

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

Can anybody tell that why this code is giving wrong answer for problem C(2112C — Coloring Game)

// clang-format off
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define endl "\n"
// I/O helpers for variables, vectors, and matrices
template<typename T> void in(vector<T>& v) { for (auto& x : v) cin >> x; }

int aaGayaCodeDekhne()
{
    int n;
    cin >> n;
    vi arr(n);
    in(arr);

    auto func = [&](int i, int j) -> int
    {
        int s = j + 1, e = n - 1;
        int ans = 0;
        while (s <= e)
        {
            int mid = s + (e - s) / 2;
            if ((arr[mid] + arr[i] + arr[j]) > max(2 * arr[mid], arr[n - 1]))
            {
                ans = mid - j;
                s = mid + 1;
            }
            else
                e = mid - 1;
        }
        return ans;
    };

    int ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            ans += func(i, j);

    cout << ans << endl;

    return 0;
}

int32_t main()
{
    int t = 1;
    cin >> t;
    while (t--)
        aaGayaCodeDekhne();

    return 0;
}

/*
1
11
27 32 35 37 45 57 65 65 71 87 96

123 - my
125 - correct
*/
»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem c, here is the two pointer implementation

def solve(a):
    count = 0
    for i in range(2, len(a)):
        l, r = 0, i - 1
        while l < r:
            if a[l] + a[r] + a[i] <= a[-1] or a[l] + a[r] <= a[i]:
                l += 1
            else:
                count += r - l
                r -= 1

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

My solution for C iterate to each i and j. Let a = arr[i] ,b = arr[j],sum = a + b Now for the third elements will be between j+1 and the last element.

So now the third element (let it be c) should meet these conditions — a + b + c > arr[n-1] and a + b > c We can find these ranges with the help of lower bound and upper bound. And by taking the intersection for each case, we add to the answer variable to get the answer. Time complexity = (n2logn)