awoo's blog

By awoo, history, 20 months ago, translation, In English

1814A - Coins

Idea: BledDest

Tutorial
Solution (awoo)

1814B - Long Legs

Idea: BledDest

Tutorial
Solution (awoo)

1814C - Search in Parallel

Idea: BledDest

Tutorial
Solution (BledDest)

1814D - Balancing Weapons

Idea: adedalic

Tutorial
Solution (adedalic)

1814E - Chain Chips

Idea: BledDest

Tutorial
Solution (BledDest)

1814F - Communication Towers

Idea: Neon

Tutorial
Solution (Neon)
  • Vote: I like it
  • +68
  • Vote: I do not like it

| Write comment?
»
20 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I know it isn't an "issue", but in problem B the variable names are a,b while here they are n,m

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

In problem B, My thought was ternary search since the values tend to decrease at first and then increase but the problem I faced is that around the middle of the curve, the values don't necessarily keep changing in the same way (X-axis for max K length and Y-axis for cost)

As you notice some irregularities, can this be handled using only ternary search or by iterating over a much smaller range of K's?

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

    I tried a weaker 1-D case (go from 0 to n)
    there $$$\sqrt{n}$$$ seems to be the best leg size. (floor or ceil I don't remember)
    (somewhat related to the fact that $$$x + a/x$$$ minimizes at $$$x = \sqrt{a}$$$ and
    similar is the case with $$$x-1 + \lceil n/x \rceil$$$)
    But ofc the problem is going up a notch to the 2-D case.
    (new to code-forces and I don't know how to write in laTex etc, pardon me for that).

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

problem EF video solution for Chinese:

BiliBili

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

Can anyone please elaborate on the solution of Problem D, please?

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

A can be solved by just checking parity of n and k

if (n % 2 == 0 || k % 2)
     yes
    else no
    
  • »
    »
    19 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can you please give an explanation of this? Also, what is meant by parity check?

    • »
      »
      »
      19 months ago, # ^ |
      Rev. 2   Vote: I like it +3 Vote: I do not like it

      parity means it's odd or even.

      if n is even, it can be made with 2 coins.

      if n is odd then k must be odd as well otherwise it is not possible.

      example

      For a more formal proof

      proof
»
20 months ago, # |
  Vote: I like it 0 Vote: I do not like it
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
void solve();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}
void solve()
{
    long long n, s1, s2;
    cin >> n >> s1 >> s2;
    long long r[n];
    vector<pair<long long, long long>> v;
    for (int i = 0; i < n; i++)
    {
        cin >> r[i];
        v.push_back({r[i], (i + 1)});
    }
    // for (auto &it : v)
    //     cout << it.first << " " << it.second << endl;
    sort(all(v));
    long long tc1 = 0;
    long long tc2 = 0;
    vector<long long> lista;
    vector<long long> listb;
    for (int i = n - 1; i >= 0; i--)
    {
        long long cost1 = v[i].first * s1;
        long long cost2 = v[i].first * s2;
        tc1 += cost1;
        tc2 += cost2;
        // cout << tc1 << " " << tc2 << endl;
        if (tc1 > tc2)
        {
            listb.push_back(v[i].second);
            tc1 -= cost1;
        }
        else
        {
            lista.push_back(v[i].second);
            tc2 -= cost2;
        }
    }
    // cout << endl;
    cout << lista.size() << " ";
    for (auto &it : lista)
    {
        cout << it << " ";
    }
    cout << endl;
    cout << listb.size() << " ";
    for (auto &it : listb)
        cout << it << " ";
    cout << endl;
}

can anyone please explain me why this code will not work for problem B?

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

    The cost is different depending on where you put it. Say that the current number of elemnts in list_a is k1, and in list_b is k2, then the cost of adding an element S is S * (k1 + 1) * S1 in the first case, and S * (k2 + 1) * S2 in the second case.

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

Can anyone tell me why we need to fix the value of K in B.

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

    Let's say we are calculating answer for $$$b$$$ only (you can extend this to $$$a$$$ also).

    Now, let's say you are using 2 values of $$$k$$$ i.e. $$$k_1 < k_2$$$. So your answer would be kind of $$$b/k_1 + b/k_2$$$, here if you just replace $$$b/k_1$$$ with $$$1$$$ you would get better answer and we can always do this since we will always increase value of $$$k$$$ from 1 to $$$k_2$$$ and $$$k_1$$$ is working on just the remainder of $$$b/k_2$$$.

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

E Has a nice observation, we would never take 3 consecutive edges. Any elegant solution using this observation.

(Take , NotTake, Take) is better than (Take, Take, Take) and both achieve our goal. f(i) = min(2*e(i,i+1) + f(i+2) , 2*[e(i,i+1)+e(i+1,i+2)] + f(i+3))

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

    Sorry for necroposting, but could you expand on how we can utilize this to quickly answer update queries? Does it still require the "classical" segment tree sol mentioned in edi?

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

Solution to problem B seems pretty complicated. Can someone please explain a simpler approach?

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

    It's not difficult. You should just know the answer is $$$\lceil\frac{a}{k}\rceil + \lceil\frac{b}{k}\rceil + (k - 1)$$$ when you add your feet to k long. Then if you remove the ceil, you can get $$$\frac{a + b}{k} + k - 1$$$, it's just an inequality $$$a + b \ge 2 \times \sqrt{a \times b}$$$ when $$$a = b$$$ the equality is achieved. Therefore, for this function, it's $$$\frac{a + b}{k} = k$$$, .i.e $$$k^2 = a + b$$$. So $$$k = \sqrt{a + b}$$$, you can get the smallest value. However, you remove the ceil, so there maybe 2 off the correct answer. You should check around. Anyway, 1e5 is enough.

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

      How did you come to the conclusion that

      (A+b)/k)=k ?

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

        Because the inequality I wrote abode. $$$\frac{a + b}{k} + k \ge 2 \times \sqrt{a + b}$$$, and when $$$\frac{a + b}{k} = k$$$ the equality takes.

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

can someone recommend more problems similar to E

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

    If the Editorial has atleast transistion states you could even try to reduce to matrix form The editorial is as good as problem statement. It's one of the kind we call it Skind S means not "shit".It means Super

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

Sorry for necroposting, but I want to share my solution of F without using KRT.

Consider doing lazy tag on rollback DSU, when we visit to a certain time, add a tag with time stamp on the representative of vertex $$$1$$$, and when we rollback(assume this edge point to $$$boss$$$), if this edge is added before the tag on $$$boss$$$ is added, then push down the tag. At the end just check whether each vertex have tag on it.

I found it is quite amazing that we can do lazy tag on DSU, maybe there also have some potential application of it?

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

Can anyone please tell me why my submission TLEs on test 5 for Problem D? It uses the same solution as editorial. Submission: 239734235

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

What is the recurrence relation used in Problem E ? what Dp transistions should one speed up ? It would be better to add equations and how they were transformed into matrix form. IMO this is the only step which is key in the matrix expo problems and Editorial is missing them

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

    Sorry for necroposting, but here are some equations I found. Notice that, of the edges you choose, you never choose 3 in a row. Therefore, there will never be more than 2 chosen edges between two unchosen edges. Also notice that you can never not choose two adjacent edges, because that will leave 1 chip in its original place. You can see that this means we must distribute unchosen edges so that they are either 1 edge or 2 edges apart from each other.

    Our answer can be expressed as two times the sum of the edges minus two times the maximum sum of edges we don't choose.

    Let's say x is one of the edges you do not choose, and _ is one of the edges you do choose. In each node of the tree, store 4 values for the segment $$$[l, r]$$$

    a. the maximum sum of x's where one x is on $$$l + 1$$$ and one x is on $$$r - 1$$$: _ x ? ? ? ? ? x _

    b. the maximum sum of x's where one x is on $$$l$$$ and one x is on $$$r - 1$$$.: x ? ? ? ? ? ? x _

    c. the maximum sum of x's where one x is on $$$l + 1$$$ and one x is on $$$r$$$: _ x ? ? ? ? ? ? x

    d. the maximum sum of x's where one x is on $$$l$$$ and one x is on $$$r$$$: x ? ? ? ? ? ? ? x

    To combine two children nodes $$$left$$$ and $$$right$$$ into a parent node, we can do this (you can draw it out to see for yourself if you need to):

    $$$parent_a = \max(left_a + right_a, left_a + right_b, left_c + right_a)$$$

    $$$parent_b = \max(left_b + right_a, left_b + right_b, left_d + right_a)$$$

    $$$parent_c = \max(left_c + right_c, left_a + right_c, left_a + right_d)$$$

    $$$parent_d = \max(left_d + right_c, left_b + right_d, left_b + right_c)$$$

    The new maximum will be the $$$\max(root_a, root_b, root_c, root_d)$$$.