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

Автор awoo, история, 13 месяцев назад, По-русски

1814A - Монеты

Идея: BledDest

Разбор
Решение (awoo)

1814B - Длинные ноги

Идея: BledDest

Разбор
Решение (awoo)

1814C - Параллельный поиск

Идея: BledDest

Разбор
Решение (BledDest)

1814D - Балансировка пушек

Идея: adedalic

Разбор
Решение (adedalic)

1814E - Фишки на цепочке

Идея: BledDest

Разбор
Решение (BledDest)

1814F - Вышки связи

Идея: Neon

Разбор
Решение (Neon)
  • Проголосовать: нравится
  • +68
  • Проголосовать: не нравится

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

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

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

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?

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

    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).

»
13 месяцев назад, # |
  Проголосовать: нравится +18 Проголосовать: не нравится

problem EF video solution for Chinese:

BiliBili

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

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

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

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

if (n % 2 == 0 || k % 2)
     yes
    else no
    
  • »
    »
    13 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

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

      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
  • »
    »
    11 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    nice solution. It takes me some time to understand your solution. How can I improve my problem solving skills?

»
13 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
#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?

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

    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.

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

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

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

    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$$$.

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

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))

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

    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?

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

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

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

    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.

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

      How did you come to the conclusion that

      (A+b)/k)=k ?

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

        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.

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

can someone recommend more problems similar to E

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

    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

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

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?

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

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

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

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