FelixArg's blog

By FelixArg, history, 13 months ago, translation, In English

Thank you for participating! I hope you enjoyed the problems.

2086A - Cloudberry Jam

Idea: Galina_Basalova

Tutorial
Solution (Galina_Basalova)

2086B - Large Array and Segments

Idea: FelixArg

Tutorial
Solution (FelixArg)

2086C - Disappearing Permutation

Idea: FelixArg

Tutorial
Solution (FelixArg)

2086D - Even String

Idea: FelixArg

Tutorial
Solution (FelixArg)

2086E - Zebra-like Numbers

Idea: FelixArg

Tutorial
Solution (FelixArg)
Solution (BledDest)

2086F - Online Palindrome

Idea: Valentin_E

Tutorial
Solution (FelixArg)
Solution (awoo)
  • Vote: I like it
  • +96
  • Vote: I do not like it

| Write comment?
»
13 months ago, hide # |
 
Vote: I like it +27 Vote: I do not like it

for E: To prove when Greedy works for the coin problem in O(N ^ 3)

link

»
13 months ago, hide # |
Rev. 4  
Vote: I like it +15 Vote: I do not like it

Before the round, I asked chatGPT to rate the difficulty of the problems, and this is what came out:

  • A: 800
  • B: 1700 pog
  • C: 1200
  • D: 1900
  • E: 2100
  • F: 1600 pog

What do you think?

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

    You mean F instead of G, right? 1600 for the problem is really underestimated, but amazing task there!

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

    D is a very standard problem so I think 1700 would be better.

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

    D1500

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

    B can't be 1700 , B required just mathematical observation, & this is how we can do it in 0(n) TC per testcases // code ~~~~~

    Spoiler

    ~~~~~

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

can someone explain the combinatorics part of D in an easier way?

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

    Let us see another problem How many ways to arrange the word "mississippi"? Now, you have $$$11!$$$ possible permutations. However, there are repeated characters in "miiiisssspp" ,for example, if all similar letters are swapped there is no change. So, you need to put into consideration the frequence of every letter so you need to divide by $$$4!$$$ twice and $$$2!$$$.

    Similarly, in our problem after the dp now you can split the string into two parts even and odd since they are independent and the number of ways is as discussed above.

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

    Basically , there are dp[odd] ways of constructing the string.

    Now if all elements were unique in this construction the number of formations would be dp[odd]! , similarly we can calculate for even as well.

    Now we know that all elements are not unique as there are repeated elements as well so we use the formula (n!/k!) which gives us the number of unique formations that are possible.(here k means the number of elements which are repeated) This will result in (odd!*even!)/(freq of each element)!

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

    This is similar to counting the number of distinct permutations of a multiset with $$$n$$$ elements, where:

    $$$n_1$$$ elements are of type $$$1$$$, $$$n_2$$$ elements are of type $$$2$$$, $$$\dots$$$, $$$n_k$$$ elements are of type $$$k$$$, and $$$n_1 + n_2 + \cdots + n_k = n$$$.

    We choose positions step by step: First, $$$ \binom{n}{n_1} = \frac{n!}{n_1!(n - n_1)!} $$$, then $$$ \binom{n - n_1}{n_2} = \frac{(n - n_1)!}{n_2!(n - n_1 - n_2)!} $$$, and so on.

    Multiplying all: $$$ \binom{n}{n_1} \binom{n - n_1}{n_2} \cdots = \frac{n!}{n_1!(n - n_1)!} \cdot \frac{(n - n_1)!}{n_2!(n - n_1 - n_2)!} \cdots $$$

    All intermediate factorials cancel out, and we get: $$$ \boxed{\frac{n!}{n_1! n_2! \cdots n_k!}} $$$

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

O(n) solution for B

void solve()
{
    ll n, k, x;
    cin >> n >> k >> x;
    vector < int > a(n);
    REP(i, n) cin >> a[i];
    ll sum = accumulate(all(a), 0ll);
    ll temp = sum;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll cnt = 1;
        ll val = x - temp;
        cnt += max(0ll,val / sum);
        if (val % sum != 0 && val>=0) cnt++;
        ans += max(0ll, k - cnt + 1);
        temp -= a[i];
    }
    cout << ans << endl;
}
  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    My O(N) solution for B:

    #include <bits/stdc++.h>
    #define ll long long int
    #define For(i, N) for(i = 0; i < N; i++)
    #define FOR(i, K, N) for(i = K; i <= N; ++i)
    #define v vector
    #define vl vector<ll>
    #define vp vector<pair<ll, ll>>
    using namespace std;
    
    void solve() {
        ll N, K, X;
        cin >> N >> K >> X;
        ll i;
        vl A(N);
        For(i, N) {
            cin >> A[i];
        }
        vl suff(N);
        ll sum = 0;
        for(i = N-1; i >= 0; i--) {
            sum += A[i];
            suff[i] = sum;
        }
        ll ans = 0;
        For(i, N) {
            ll num = max(X - suff[i], (ll)0);
            num = num/sum + (num%sum != 0 ? 1 : 0);
            ans += max(K-num, (ll)0);
        }
        cout << ans << '\n';
    }
    
    int main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        ll T = 1;
        cin >> T;
        while(T--) {
            solve();
        }
        return 0;
    }
    
»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

FelixArg you got any idea which problems gpt o3 mini high solves before proposing the contest , also which problems are they

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

    Yeap, I checked which problems can be solved by o3-mini-high, it turned out that all but F :(

    I think it's because in almost all problem statements were highly formalized, and the problems themselves are more educational than in regular div2.

    Now GPT is very good at solving problems, and authors have to either mess up statements or put up with it.

    I believe that contests are created to enjoy solving problems without help, not to chase high rankings by all available methods, including unfair use of GPT.

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

Can someone explain why the following approach does not work for E:

Zebra numbers are numbers of the form 111...111 in base 4. This is equivalent to $$$\frac{4^p - 1}{3}$$$ for some $$$p \gt 0$$$. This implies that for a number $$$x$$$ to have a zebra value of $$$k$$$, it is necessary and sufficient that sum of the digits in the base 4 representation of $$$3x + k$$$ must be equal to $$$k$$$. We can set $$$L = 3l + k$$$ and $$$R = 3 r + k$$$. We define our dp to find all numbers less than a number $$$X$$$ which have a zebra value of $$$k$$$ as follows:

$$$dp[pos][sum][tight]=\sum_{i = 0}^{tight?X[pos]:3} dp[pos + 1][sum + i][tight \& [i = X[pos]]]$$$

With

$$$dp[|X|][sum][tight] = [sum = k]$$$

Note that in the implementation, we must be sure that the final digit is zero, as we cannot have $p = 0$ since $$$\frac{4^p - 1}{3}$$$ would be equal to $$$0$$$. Subtracting the dp value for $$$X = L - 1$$$ from $$$X = R$$$ should give the correct result, but it does not. Can anyone point out the flaw in my reasoning?

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

    I had the same approach and the flaw here is that you can take each zebra upto 4 times. Eg answer for (4^m-1)/3-1 is 4. So base 4 doesn't quite work. I don't have a fix for this yet.

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

Note: D can be solve with meet in the middle, which, while slower for this problem, passes no matter what the constraint on the sum of the number of characters is.

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

In problem D we should divide not by the product of the elements of vector c, but by the product of the factorials of the elements of this vector. (In tutorial part. Code solution is ok)

Just add factorials to formulas

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

I solved D — Even String problem using a different approach.

The key observation is that every character in the string must be placed either in even or odd indices. This allows us to reduce the problem to a standard "pick-or-leave" DP problem.

Let $$$dp[i][j]$$$ represent the number of ways to arrange the last $$$i$$$ characters such that there are $$$j$$$ remaining even indices.

Since each character must be placed entirely in either even or odd positions, we don't need to track the number of remaining odd indices in the state—it's implicitly determined. So, let $$$k$$$ be the number of remaining odd indices.

The transition becomes: $$$dp[i][j] = dp[i + 1][j - c[i]] * C(j, c[i]) + dp[i + 1][j] * C(k, c[i])$$$, where $$$c[i]$$$ is the count of character $$$i$$$ and $$$C(a, b)$$$ denotes "$$$a$$$ choose $$$b$$$". The idea is simple: if we decide to place character $$$i$$$ in the even indices, we have $$$C(j, c[i])$$$ ways to do it using $$$j$$$ available even positions; similarly, if we place it in the odd indices, we have $$$C(k, c[i])$$$ ways using $$$k$$$ odd positions. We multiply these counts with the respective DP values to accumulate the number of valid configurations.

My solution Code

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

Speedforces handled A, B, C — D tried, but got speedforced too!

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

Alternate solution for D:

Let $$$dp(i, j, k)$$$ be the number of strings you can make from the first $$$i$$$ letters if there are $$$j$$$ even positions and $$$k$$$ odd positions. Then:

$$$dp(i, j, k) = dp(i-1, j - c[i], k) \cdot \binom{j}{c[i]} + dp(i-1, j, k - c[i]) \cdot \binom{k}{c[i]}$$$

We can optimize this by realizing that $j+k = c[1] + c[2] + ... + c[i]$. So we can drop the $$$k$$$.

Code: 313882724

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

FelixArg the editorial is not attached to the contest problems.

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

thanks for the round! perfect problems

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

There's an easier way to solve problem B. Just use a suffix and see how many "full arrays" you need infront of that suffix so that the sum is larger than or equal to X. Code: https://mirror.codeforces.com/contest/2086/submission/314026288

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

Can we solve C using graphs? If YES, then how? Can someone share sol?

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

I want to explain the brute force for F.

In the tutorial of F,it said "however, deriving them manually is quite complicated, as there are many situations."

But I consider this problem as a perfect chance to practice case work:

Do the first three letters by case work.

First, whether $$$s_1$$$ is 'a' or 'b' doesn't matter.

We can just record the longest 'ababab' prefix and the value of $$$s_{mid}$$$ ,and do case work. Do two letters $$$x,y$$$ once.

  1. p=1; p is odd number ;p is even number
  2. $$$s_1=s_{mid}$$$,$$$s_1\neq s_{mid}$$$
  3. $$$p=mid-1$$$,$$$p\neq mid-1$$$
  4. $$$x=a$$$,$$$x=b$$$
  5. $$$y=a$$$,$$$y=b$$$

In the $$$p=1$$$,we don't care $$$p=mid-1$$$.

As in the code,there is $$$2\times 2 \times 2+2\times 2\times 2\times 2\times 2=40$$$ cases,handle them one by one and get c++ code in 15kb.

I highly recommend you to read code, and I'm glad you to find my mistakes.

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

Cannot understand why If the greedy algorithm works for all numbers less than y , then in the decomposition of the number y , there must be at least one number zi−1 .

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

    Suppose the greedy algorithm works for all numbers less than $$$y$$$, but not for $$$y$$$. Then, the partition of $$$y$$$ should start with some number $$$z_j$$$ such that $$$j \lt i$$$. If $$$j = i-1$$$, case closed.

    Otherwise, the partition of $$$y$$$ consists of the number $$$z_j$$$ and the partition of $$$(y - z_j)$$$ such that $$$z_j \le z_{i-2}$$$. Since $$$y \ge z_i$$$, it means that $$$y - z_j \ge z_{i-1}$$$. So, the greedy partition of $$$(y-z_j)$$$, which is optimal by our assumption, starts with either $$$z_i$$$ (then $$$y$$$ can also be greedily partitioned) or $$$z_{i-1}$$$ (then $$$z_{i-1}$$$ is included in the optimal partition of $$$y$$$).

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

I had a problem in the Problem F.

How to prove that we could add two characters in any cases, when I could not find the general cases by my hand. In other words, why could brute-force find the method necessarily?

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

Problem D, could also be solved using MEET-IN-THE-MIDDLE, with a TC = $$$O(2^{14} + n/2 )$$$
As, we can brute force on first 13 characters, within reasonable time constraints, then we are left with just some standard MITM algo. implementation, where we take "i" even from first set and find the complementary part from the other, and apply the combinatorial formula, and add it to our answer.

Here's my code : submission

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

Why in the second problem author have taken r = n*k fixed, can't it change for some other x where a subarray from between the b array be selected?