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

Автор qwexd, 2 месяца назад, По-английски

Codeforces Round 1121 — Editorial

Thanks for participating!

2264A - Рамбу нужна рука

Problem by qwexd.

Hint
Solution
Code (GNU C++17)

2264B - Ферма пилюль Найфа

Problem by qwexd.

Hint 1
Hint 2
Solution
Code (GNU C++17)

2264C - Династия фигуристов Мадамант

Problem by qwexd.

Hint 1
Hint 2
Solution
Code (GNU C++17)

2264D - Тёмная тема доктора Агоса

Problem by qwexd.

Hint 1
Hint 2
Hint 3
Solution
Code (GNU C++17)

2264E1 - Простое наводнение (простая версия)

Problem by qwexd.

Hint 1
Hint 2
Hint 3
Solution
Code (GNU C++17)

2264E2 - Простое наводнение (сложная версия)

Problem by qwexd and solved for bigger constraints by jeroenodb.

Hint 1
Hint 2
Hint 3
Solution
Code (GNU C++17)

2264F - Калькулятор беспорядков

Problem by jeroenodb. Testing tool created by turska

Hint 1
Hint 2
Hint 3
Solution
Code (PyPy 3)
Code (PyPy 3) simplified and golfed
Разбор задач Codeforces Round 1121 (Div. 2)
  • Проголосовать: нравится
  • +149
  • Проголосовать: не нравится

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

F can be solved in 1661 characters

Solution by ChatGPT: 390658725

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

Deleted

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

Got it

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

As an author, thanks for participating! I am pretty curious how small expressions for problem F you can get. The editorial is in no way the best approach, but it was the original way I solved the problem. Testers already found some different approaches.

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

Sleepforces

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

COMBINAforces

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

Great problems!

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

I am a bit surprised my approach 390666998 upsolving F was not the intended one, since I think mine relies on less esoteric knowledge. The closed-form formula $$$D_k = k!\sum_{i=0}^k \frac{(-1)^i}{i!}$$$ (which I think is standard/well-known?) can be rewritten $$$\sum_{i=0}^k (-1)^{k-i}\frac{k!}{(k-i)!}$$$ which expands to $$$(-1)^k\left(1-k+k(k-1)-k(k-1)(k-2)+\cdots\right)$$$ and crucially we can extend this to any number $$$ \gt k$$$ terms, since any term with $$$k-k$$$ is zero. We can group terms to make this $$$(-1)^k\left(1-k(1-(k-1)(1-(k-2)(\cdots)))\right)$$$ which for the first $$$n+1$$$ terms makes a string of size $$$O(n^2)$$$. The $$$(-1)^k$$$ is the only part that actually needs rounding here, in order to extract the bottom bit.

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

My solution for D:

if (n == 1) cout << "1" << '\n';
    else if (n == 2) cout << "11" << '\n';
    else if (n == 3) cout << "101" << '\n';
    else if (n == 4) cout << "0101" << '\n';
    else if (n == 5) cout << "10101" << '\n';
    else {
        string ans;
        string x((n - n % 6) / 3 - 1, '0');
        if (n % 6 == 0) {
            ans = x + "1" + x + "1" + x + "1";
        }
        else if (n % 6 == 1) {
            ans = x + "1" + x + "1" + x + "01";
        }
        else if (n % 6 == 2) {
            ans = x + "01" + x + "1" + x + "01";
        }
        else if (n % 6 == 3) {
            ans = x + "001" + x + "1" + x + "01";
        }
        else if (n % 6 == 4) {
            ans = x + "1" + x + "001" + x + "001";
        }
        else if (n % 6 == 5) {
            ans = x + "01" + x + "001" + x + "001";
        }
        cout << ans << '\n';
    }

I did brute-force for first 20 n and notice the pattern...

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

    my solution:

    i had already known till 6 (which is trivial). then understood that if total number of 0s for case of 1 is bigger than 3 then one of the 1 will be at the end. then just compare the optimal 2 vs optimal 3 solution. ~~~~~ void solve() { int n;

    cin >> n;

    if (n < 7) {

    fora(i, 0, (n / 2) * 2, 2) { cout << "10"; }
    
    if (n & 1)
    
      cout << "1";
    
    return;

    } else {

    int z2 = n &mdash; 2;
    
    int div2 = z2 / 3;
    
    int rem2 = z2 % 3;
    
    ll two = 0;
    
    al(3) arr2{div2, div2, div2};
    
    rep(i, rem2) arr2[i]++;
    
    if (rem2 == 0 and div2 % 2 == 0) {
    
      arr2[0]--, arr2[1]++;
    
    }
    
    rep(i, 3) two += (arr2[i] * (arr2[i] + 1)) / 2;
    
    int z3 = n &mdash; 3;
    
    int div3 = z3 / 3;
    
    int rem3 = z3 % 3;
    
    ll thr = 0;
    
    al(3) arr3{div3, div3, div3};
    
    if (rem3 == 0 and div3 % 2 == 0) {
    
      arr3[1]--, arr3[2]++;
    
    } else if (rem3 == 0 and div3 % 2 == 1) {
    
      arr3[0]--, arr3[2]++;
    
    } else {
    
      rep(i, rem3) arr3[i]++;
    
      if (div3 % 2 == 0) {
    
        swap(arr3[0], arr3[2]), swap(arr3[1], arr3[2]);
    
      } else {
    
        swap(arr3[1], arr3[2]);
    
      }
    
    }
    
    rep(i, 3) thr += (arr3[i] * (arr3[i] + 1)) / 2;
    
    thr += arr3[1] + 1;
    
    if (two < thr) {
    
      rep(i, arr2[0]) cout << '0';
    
      cout << '1';
    
      rep(i, arr2[1]) cout << '0';
    
      cout << '1';
    
      rep(i, arr2[2]) cout << '0';
    
    } else {
    
      cout << '1';
    
      rep(i, arr3[0]) cout << '0';
    
      cout << '1';
    
      rep(i, arr3[1]) cout << '0';
    
      cout << '1';
    
      rep(i, arr3[2]) cout << '0';
    
    }

    }

    }

    ~~~~~

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

I had a different approach to C:

You can build the answer iteratively, processing values from largest to smallest. Maintain the sum of all values already added ($$$sum$$$) and the number of valid trees that can be formed so far ($$$ways$$$).

When considering the $$$k$$$th largest node (assume 0-indexing), it can be attached below any of the $$$k$$$ existing nodes. Therefore, whatever the running answer was before should be multiplied by $$$k$$$, since every previous tree now produces $$$k$$$ new trees distinguished only by node $$$k$$$'s parent.

Furthermore, across those $$$k$$$ possible parent choices, node $$$k$$$ contributes $$$\sum\limits_{v}{(v - a_k)} = sum - k(a_k)$$$. Multiply this quantity by $$$ways$$$ (before updating it) to account for making these attachments in every previously valid tree.

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

In D — anyone care for explaining why we didn't trynna break the blocks into 4 chunks with 3 ones?, and even when we did use 3 ones we put the last one at the end, essentially just creating 3 blocks of zeroes.

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

    look at the prefix sum modulo 3, it is either 0 or 1 or 2. So if you create 4 blocks, there must be two block with the same modulo. Their contribution to the number of subarray is still number of pair (l, r) which have the same prefix sum...

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

    look at the prefix sum modulo 3, it is either 0 or 1 or 2. So if you create 4 blocks, there must be two block with the same modulo. Their contribution to the number of subarray is still number of pair (l, r) which have the same prefix sum...

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

Another solution for F: Consider the recurrence $$$D_i = i \times D_{i-1} + (-1)^i$$$, which can be adapted as $$$D_i = (1 + (i-1) \times [n \geq i]) \times D_{i-1} + (-1)^i \times [n \geq i]$$$. A naive implementation of this approach (representing each number as $$$\frac{n+n+\cdots+n}{n}$$$) can result in a solution with a little bit more than 10000 characters. To get AC, we can use DP to minimize the length of the string used to represent each number. See: 390750464

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

i dont get it bruh , i am stuck at 1000-1100 and it sucks doing permutation ques everyday and still not able to get them right, somehow the way of solving or the concept is totally different....no perfect ladder to climb man!

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

A difficult div2, but nice problem

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

I have a dp solution for problem C more or less it's a contribution technique . well we can define dp[i] as the sum of all valid dinasty trees with nodes containing n , n-1 , .. , i .

talking about transition when we are adding the ith node to the tree we can have n , n-1 , n-2 , .. i+1 as its parents assuming the array is in sorted order .

so dp[i] = (n-i)*dp[i+1] + factorial(n-1-i) * (pref[j] — pref[i] — (n-1)*a[i]) ; where pref array is the partial sum of array a . (n-i) is the no of all the nodes which are greater than ith node and factorial(n-1-i) is the number of different trees we have formed so far so each node a[j] — a[i] would contribute to factorial(n-1-i) times when adding ith node .

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

WHY E2 2700?