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

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

Спасибо за участие! Надеюсь задачи вам понравились.

2086A - Варенье из морошки

Идея: Galina_Basalova

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

2086B - Большой массив и отрезки

Идея: FelixArg

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

2086C - Исчезающая перестановка

Идея: FelixArg

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

2086D - Четная строка

Идея: FelixArg

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

2086E - Зебристость чисел

Идея: FelixArg

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

2086F - Онлайн палиндром

Идея: Valentin_E

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

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

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

link

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

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?

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

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

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

    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.

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

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

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

    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!}} $$$

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

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

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

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

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

    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.

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

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?

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

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.

»
18 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится +8 Проголосовать: не нравится

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

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

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

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

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

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

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

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

FelixArg the editorial is not attached to the contest problems.

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

thanks for the round! perfect problems

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

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

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

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://codeforces.me/contest/2086/submission/314026288

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

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

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

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.

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

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 .

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

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

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

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

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

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?

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

My approach for problem D:

so let's say we have a grp of similar character with size x > 1 then all these characters will be on the even indices or odd indices(all of them) , so what we can do is we can handle odd and even indices seperatly so the permutations of the odd side are (fact[(n+1)/2]/(x)) , where x is the product of factorials of group size for each character at odd position , and indeed we can find similar for the even indices which is (fact[n/2])/(y), where y has the similar meaning to x but for the even indices , now the answer for the problem will be (odd_part*even_part)*(cnt), and also rememver that we are doing everything under modulo so there may be inverse also,

now let's talk about the "cnt" that i have written , cnt refers to the number of exchanges that you can do between the odd and even indices , say there is a group of size 4 on odd side and there are two groups of size 2 on the even side then you can simply exchange them between odd and even part, so now how do we calculate cnt?, basically it is the same as counting the subsequences that have sum n/2, because all the c_i's at even positions have a sum equal to n/2, so we can count the number of subsequences in O(2^(26)) , ik TLE is waiting for me because test case <= 1e4....

I just want to know whether this approach is correct or not??

Here is my code