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

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

Мы надеемся, что вам понравился контест! Спасибо вам за участие! Для нас это третий официальный раунд, поэтому мы были бы рады услышать ваши отзывы в комментариях и в мини опросе ниже.

Как вам контест?
Какие задачи вам понравились (можно выбрать несколько)?
Какие задачи вам не понравились (можно выбрать несколько)?

2184A - Социальный эксперимент

Идея: fstilus; разработчик: fstilus

Подсказка
Разбор
Решение

2184B - Песочные часы

Идея: fstilus; разработчик: fstilus

Подсказка
Разбор
Решение

2184C - Огромная куча

Идея: Friendiks; разработчик: fstilus

Подсказка 1
Подсказка 2
Разбор
Решение

2184D - Нечестная игра

Идея: Friendiks; разработчик: Friendiks

Подсказка 1
Подсказка 2
Подсказка 3
Разбор
Решение
Бонус

2184E - Изысканный массив

Идея: fstilus; разработчик: fstilus

Подсказка 1
Подсказка 2
Подсказка 3
Подсказка 4
Подсказка 5
Подсказка 6
Разбор
Решение

2184F - Вишнёвое дерево

Идея: gravitsapa; разработчик: gravitsapa

Подсказки для первого способа
Подсказки для второго способа
Разбор
Решение 1
Решение 2

2184G - Мерзость отрезков

Идея: Friendiks; разработчик: Friendiks

Подсказка 1
Подсказка 2
Подсказка 3
Подсказка 4
Разбор
Решение
Разбор задач Codeforces Round 1072 (Div. 3)
  • Проголосовать: нравится
  • +30
  • Проголосовать: не нравится

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

Bad contest for me, I struggled on B!

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

E can actually be addressed in O(n) easily.

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

Problems were hard T-T

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

Posted editorial faster then judging solutions lol!!, unnecessary penalties because of the lag.

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

im dead

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

those problems are so good!

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

Tutorials of D and G not understandable.

What is D about, what does it ask for?

What "function" is there in G?

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

E can be solved with monotonic stack for contribution in O(n) 357602037

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

Felt like a div 2

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

Great contest, my first AK on div3 <3.

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

ive been grinding 1500-1700 in an effort to reach expert and i really thought i was making some progress. i mean, i solved many questions on my own. if not, i was able to atleast get close to the key observations.

and yet i could not solve B and C. even after trying for nearly an hour.

if my math is really this weak, there is no hope of me ever actually getting good at CP, is there? im cursed to never actually improve. all the questions i solved were probably very easy with inflated ratings. or it was just a fluke.

i have had bad contests but this one was the worst. maybe i should just go back to doing LeetCode

EDIT: turns out my mistake for B was that i accidently inverted the if-else conditions and for C i simply missed the case where n == k. i shouldnt have given up so quickly lol. oh well

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

    practise makes man perfect. Believe in yourself, consistency is the key.

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

    Nah, it's fine... bad contests happen. for me as well, that was the worst contest I've done in months (and I'm doing virtual Div. 3 pretty often ), so... don't let yourself down over just one bad contest :) There is no such thing as "never improving", you just need to compare yourself with yourself from a month ago / year ago for seeing how much you have improved, this here is just a rating that while it should show "how much you improved" it just shows how prepared you were on some specific type of problems ( in this case math ), so yeah, maybe it's just time for both of us to learn some more math tricks on cf, not to give up <3

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

    chill, it isn't that deep, just understand the solutions and learn from your mistakes

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

    Just do CSES? You're probably lacking foundational skill, Codeforces teaches a lot of dumb tricks, it's inefficient to just do a bunch of questions on CF. I'd do something like CSES and USACO Guide if I had to start over, since that's what got me to 1200 in like 4-5 months. You need to categorically learn every technique, not just do a bunch of questions and hope for the best. Grinding CF can help, but it's mostly about learning to discover insights faster, it's very tough to learn all the fundamentals from just CF.

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

For problem 2184C — Huge Pile, any way to avoid tle here? ~~~~~ const ll mx = 1e7+123; ll dp[mx]; ll f(ll n, ll k) { if (n == k) return 0; if (n < k) return inf; if (n < mx && dp[n] != -1) return dp[n];

if (n % 2 == 0) {
    ll z1 = f(n / 2, k);
    if (z1 == inf) {
        if (n < mx) return dp[n] = inf;
        else return inf;    
    }
    else {
        if (n < mx) return dp[n] = 1 + z1;
        else return 1 + z1;;    
    }
}

ll z1 = f(n / 2, k);
ll z2 = f(n / 2 + 1, k);
if (z1 == inf && z2 == inf) {
    if (n < mx) return dp[n] = inf;
    else return inf;    
}
if (z1 == inf) {
    if (n < mx) return dp[n] = 1 + z2;
    return 1 + z2;
}
else if (z2 == inf) {
    if (n < mx) return dp[n] = 1 + z1;
    return 1 + z1;
}

if (n < mx) return dp[n] = min(1 + z1, 1 + z2);
return min(1 + z1, 1 + z2);

}

void solve() { ll n, k; cin >> n >> k; // dbg(f(3, 4));

memset(dp, -1, sizeof(dp));

ll res = f(n, k);
if (res >= inf) cout << -1 << endl;
else cout << res << endl;

} ~~~~~

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

    n can go till 1e9, you need to think better

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

    I solved like this, avoided tle:

    // Anshul Gaharwal 007
    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define ll long long
    #define inf INT_MAX
    #define pb emplace_back
    #define ll_inf LLONG_MAX
    
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        int tc;
        cin >> tc;
        while (tc--)
        {
            ll n, k;
            cin >> n >> k;
            queue<pair<ll, ll>> q;
            unordered_set<ll> s;
            q.emplace(n, 0);
            s.insert(n);
            ll res = -1;
            while (!q.empty())
            {
                auto val = q.front();
                if (val.first <= k)
                {
                    if (val.first == k)
                    {
                        res = val.second;
                    }
                    break;
                }
                q.pop();
                if (val.first % 2 == 0)
                {
                    val.first /= 2;
                    if (val.first == k)
                    {
                        res = val.second + 1;
                        break;
                    }
                    else
                    {
                        if (s.find(val.first) == s.end())
                        {
                            q.emplace(val.first, val.second + 1);
                            s.insert(val.first);
                        }
                    }
                }
                else
                {
                    val.first /= 2;
                    if (val.first == k)
                    {
                        res = val.second + 1;
                        break;
                    }
                    else
                    {
                        if (s.find(val.first) == s.end())
                        {
                            q.emplace(val.first, val.second + 1);
                            s.insert(val.first);
                        }
                    }
                    val.first++;
                    if (val.first == k)
                    {
                        res = val.second + 1;
                        break;
                    }
                    else
                    {
                        if (s.find(val.first) == s.end())
                        {
                            q.emplace(val.first, val.second + 1);
                            s.insert(val.first);
                        }
                    }
                }
            }
            cout << res << endl;
        }
    }
    
»
8 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Liked B

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

    Same, I wrote down some simulations and got the answer quite quick.

    I hated A's phrasing though, solved all the way through D before finally understanding what A was asking for (then promptly solving it in one-shot) :<

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

357546787

Did I get a wrong TLE here? I submitted pretty much the same with just making the values very marginally smaller, and I'm pretty sure this shouldn't be close to TLE. (This worked: 357553381)

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

Problem F and G felt more like an educational round problem. I liked the idea of the query always being 0 or 1.

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

using dsu for merging segments in E is a nice trick which I learned, v elegant!

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

iam i the only one who found B really hard (kinda impossible) i couldn't even understand it it feels bad tbh iam the only one who thinks its problem statement is poorly typed

for example i couldn't solve problem C but at least i get that it is on my skill that i couldn't figure the math idea behind it but for problem B i couldn't even figure out what is it asking me to do !

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

357562263

Problem G's tests can be done with O(NQ) (when it's not supposed to) with proper breaking after cumulative minimum values — wish the testcases there were stronger on that one since the very reason why we implemented the segtree in the first place was to stop Naive simulation

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

I think I got pretty close to D, but I can't figure out where my code's going wrong- I'd be grateful if anyone took a peek at it. 357620086

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

I had fun trying to solve A for 2 hours with my limited knowledge

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

For some reason i was really convinced that bfs would give tle in C, so i tried to come up with some solution using the bits in n and k.

First, there was a special cases: $$$k=2^d$$$ for some d, and there were a prefix of $$$n$$$, $$$n'$$$, in which $$$n'= 2*2^d -1$$$ then it can be done in $$$log_2(n)-log_2(n')+1$$$ operations, the cost of transforming $$$n$$$ into $$$n'$$$ with floor operations and then making a ceil operation for clearing the ones in $$$n'$$$.

Now, analyzing the binary representation of $$$n$$$ and $$$k$$$, and their prefixes:

If $$$k$$$ is a prefix of $$$n$$$ in their binary representation, then it can be done in $$$log_2(n)-log_2(k)$$$ operations.

Now, if they differ in some bit b in which b is 1 in $$$n$$$ and 0 in $$$k$$$, we would need to turn this bit off in $$$n$$$, which is not possible with our operations while maintaining it in the final result.

But if b is 0 in $$$n$$$ and 1 in $$$k$$$, we can only turn b into a 1 in $$$n$$$ if we "borrow" some less significant bit of $$$n$$$ that is 1, but this borrowing forces all bits that are less significant then b to be 0 (if they can still be present after the borrowing). So for this last case, we need to check if all bit less significant then b in $$$k$$$ are 0. Also, let $$$c$$$ be this number of 0s in $$$k$$$, so $$$n$$$ needs to have a sequence of ones of size $$$k$$$ right after the bit b and also have an additional 1 to be borrowed. If all of these conditions are valid, then it can also be done in $$$log_2(n)-log_2(k)$$$.

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

For me B > C C is stright forward but B needs some good thinking...

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

dsu fucker ah

(y is ts wrong)

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

My first CF contest able to solve 2 questions (A and C) .

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

Just B took me a whole hour... I really liked it though, but my solution wasn't as elegant as the editorial's

ll s,k,m;cin>>s>>k>>m;
ll secs=m%(2*k);
cout<<(secs<k?max({s-secs, s-k, 0ll}):(max(min(s,k)-(secs-k), 0ll)))<<'\n';

Any tips for avoiding min/max stuff and finding the elegant "shortcuts"? I always end up with verbose "unminimized" code.

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

Dude Contest was actually hard. B was literally tougher than C. C was kinda straightforward could've accepted in one submission but i missed edge case of n==k. I need to practice so much :(

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

I need to up solve more. B made me have a stroke. That Div 3 B question was harder than the previous Div 1/Div 2 questions: A, B, C of the Blacksled contest.

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

Unintentionally, skipped the fact that $$$n = 2^x$$$ in problem D and was trying to solve the bonus version the whole time... feels so bad :(

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

Pretty bad contest for me, but I guess it’s a good time to pick up some cool math tricks.

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

I solved D using a completely different approach. It’s a somewhat unconventional math/pattern-based enumeration solution, ofc not the intended one, but it works and it shows the beauty of Fibonacci sequence.

Dropping my accepted submission here just in case anyone is curious about an alternative way of thinking. Not for learning purposes! For that the editorial approach is far better ig. Submission: 357624461

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

For C, I had a different solution based on bitwise.

If we have the desired value K, it will require either 2*K-1, 2*K or 2*K+1 to be formed before K can be formed, as any one of 2*K-1, 2*K, 2*K+1 divides into K. This means we are looking for a way to make N with 2^x * K + A[x-1] * 2^(x-1) + A[x-2] * 2^(x-2) + ... + A[0] * 2^0, where A[i] has value -1, 0 or 1. This is a trope I recall seeing in another problem, just that I can't remember exactly which one it is now.

Now, how do we test for this? We iterate i=0 to 64 until N — (2^i * K) is equal to or smaller than 2^i — 1 (because this is the max we can form as the A[i] * 2^i sum). If N is greater than (2^i * K) — (2^i — 1), since that is now the minimum sum we can achieve with 2^i * K, then K will be formed from N in exactly i operations, otherwise, there is no solution.

Time O(1), memory O(1)

Code:

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

d can be also done using dp

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

Is $$$nlog^2n$$$ supposed to TLE in G? I solved without using 'walk on segment tree', but my solution got hacked.

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

My solution for C is very different

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

Pretty difficult contest, B was quite annoying.

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

Problem F and G felt too standard.(I am not really complaining) But I think particulary G should involve something more tricky(even if educational) than just using one simple observation and bam segment tree.....AC. overall I enjoyed solving problem E the most.Used segment tree for E as well as I couldn't come up with the merging thing.

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

G is cool task

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

For problem D , The number of integers $$$0 \leq m \leq 2^d$$$ such that $$$\text{maxBit}(m) + \text{cntBit}(m) = k$$$ is on A027926 on oeis. Interestingly, the number of unbounded integers $$$m$$$ such that $$$\text{maxBit}(m) + \text{cntBit}(m) = k$$$ is the k'th fibbonacci number.

I only found this because I misread the problem to say alice divides by the largest power of 2 in the prime factorization of n when n is even instead of just dividing by 2. The answer for this different problem comes out to $$$\sum_{i=k+1}^{n} {{d-1}\choose{\lfloor \frac{i}{2} \rfloor}}$$$. When I realized my misread I found the oeis sequence when adapting the solution.

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

Thanks for fast editorial and beatiful contest. Problem D was amazing! It actually blew my mind.

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

Also, I think C was much easier than B

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

great problem setting, absolutely loved it!

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

i didnt expect to solve only 2 questions in div3 . looking at the edi now the problems seem so interesting

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

G would be C if it wasn't for data structures

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

how long does it take for ratings to change since I am new at code forces , I have solved a lot in CodeChef and lc and other platforms bt I dont know about this , if anyone can help it will mean a lot

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

D can be solved in $$$O(1)$$$ each query

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

Since I solved fewer problems in div3 than in div2, f**king!

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

D can be solved using digit dp ,first convert the number into its bits form and then use the condition that 2*setbits-1+unsetsbits<=k 357599309 ,you can check my last submission

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

B was quite tricky!

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

Problem B.

why for test case

16 7 7 answer is 7? (not 9)

There is only one flip. After flip sand minute s — k = 9. No one does flip anymore.

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

Tho I didn't perform well, one of the best div3s I have given so far

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

E can be solved using two maps , one for left and one for right , and then counting contribution for each k , and updating left and right ranges in map . B was tricky .

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

This was my First contest, Im happy that I've solved 3 Questions, I hope that Ill improve.

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

another sol for C

Code

link: https://codeforces.me/contest/2184/submission/357635822

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

Solved B in 5 minutes, C in 10 minutes, but didn't solve A in a whole contest lol. The weirdest performance ever

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

Ratings are out?

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

I am not able to figure out why my solution for D, 357586842 got hacked please help

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

Your text to link here... I don't understand why my code failed in Test 2. Could some expert help me find the bug? Thank you.

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

B was extremely weird

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

Alternative solution for C:

We can greedily select the next value.

If we can just construct the k with the current n (1 step) we just end the loop.

if n % 2 == 0 it is obvious that we will go to n / 2

if n % 4 == 1 we should go to n / 2 + (n % 2) because it is obviously a better choice than n / 2.

if n % 4 == 3 vice versa

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

I saw many submission who used a segment tree in problem E.

Can anyone explain how to do it using a segment tree?

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

Why is it showing as unrated competition for me?

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

In my sleep deprived mind I thought of just checking for half population one side and another half another side for A, but I was too frustrated with my failed submissions and I gave up in between. Should have tried it.

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

What is "rnk" in solution of problem E

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

E can be solved without dsu, set or stack. I solved it just using arrays. 357749120 I follow the same strategy as mentioned in the editorial. It can be noted that when we arrive at an index to merge two segments, we only need the left and right segment lengths about that index. So we can maintain a segment_start array and a segment_end array. segment_start[i] = length of segment which starts at i. segment_end[i] = length of segment that ends at i. We can update the arrays as we merge two segments using the lengths. Check my submission for understanding.

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

How does the suggested solution for G (descent approach) has the time complexity of $$$O(n + qlogn)$$$ ? I think, it should still be $$$O(n + qlog^2n)$$$. Because one $$$logn$$$ factor comes from the fact that we are doing binary search and the second $$$logn$$$ factor will be used for checking the sign of the $$$h(d)$$$ function at the points $$$c_l$$$ and $$$c_r$$$ at each point during the binary search.

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

Here's an alternate soln of D, O((logn)^3)

#include <bits/stdc++.h>
using namespace std;

int rec(int i,int sum, vector<vector<int>> &dp){
    if(i>0 && sum ==0){
        return 0;
    }
    
    if(i==0){
        return 1;
    }
    if(dp[i][sum]!=-1){
        return dp[i][sum];
    }
    int ans1 =0;
    ans1 = rec(i-1,sum-1,dp);
    
    int ans2 = 0;
    if(sum>=2){
        ans2 = rec(i-1,sum-2,dp);
    }
    
    return dp[i][sum] = ans1 + ans2;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    cin >> T;
    while (T--) {
        
        int n,k;
        cin>>n>>k;
        
        int ans =1;
        
        int final =-1;
        for(int i=1;i<31;i++){
            //fixing this
            if(n&(1<<i)){
                final = i;
                break;
            }
            int sum = k-1;
            
            if(sum > 2*i){
                sum = 2*i;
            }
            
            vector<vector<int>> dp(i+1,vector<int> (sum+1,-1));
            ans += rec(i,sum,dp);
            dp.clear();
        }
        
        if(final+1 <=k){
            ans++;
        }

        if(ans >n){
            cout<<0<<"\n";
        }
        else{
            cout<<n-ans<<"\n";   
        }
        
    }
    return 0;
}
//
»
8 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hey everyone ! can anyone please say where to practice problems for improving my problem solving efficiency in contests . and practicing methods which u felt good .currently my rating is 1000 .i wish to improve it kindly help me out .

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

    Hey, a sophomore here!

    I have been relatively active in the platform for multiple months and I believe this might help you out.

    1. Problems to practice can be found across multiple websites. I recommend you to try Hackerrank, CSES problem set(highly recommended) and leetcode(standard across Indian engineering institutes to practice for placements and a lot more).

    2. Problem efficiency doesn't arise from sheer talent or the number of problems you have solved in the past for your future. It's the underlying maths which you're able to apply on that carries you forward.

    1. Also, this is about rating: Ratings are not marks in the first place. Just a signal about how good or progressive the user is in the platform. Most yearn for ratings, and the process to improve it spans from multiple weeks to possibly, multiple months. Consistent efforts and the ability to apply maths compound gradually unless you don't learn the concepts involved in a problem properly.

    Here's an extra suggestion for you: Write formal math proofs for problems you come across especially for datastructures.

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

it was tuff asf..could not solve B..also got A wrong coz of panic and language problem...i think framing of question language is better in div 2

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

I felt that the previous Div 2 a,b questions were much easier than this Div 3 contest.

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

The author's solution to G by method of descending is really elegant.

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

For me it was great contest and first oroblem is soososooooooooooo easy

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

I checked EFG and it's not very difficult. Is ABCD more difficult than EFG?

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

can someone provide the ratings of each ques

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

my approach for problem c

// this is code
#include <bits/stdc++.h>
using namespace std;

int solve(int n, int k, int t) {
    if (n < k) return -1;      
    // if(n==k)return t;
    int a = n / 2;
    int b = n - a;
    if(k==a || k==b)return t+1;
    int num = a;
    if(a!=b){
        num = a%2==0?b:a;
    }
    int ans = solve(num, k, t + 1);
    return ans;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        if(n==k){
            cout<<0<<endl;
            continue;
        }
        int ans = solve(n, k, 0);
        cout << ans << endl;
    }
}

whenever i decompose a number i check if decomposed number is my target,and if not among the decomposed number i take the odd number because on decomposition of these i will get all the possible factor and can ignore the other number please take a example you will understand,although i am sillly mistake person i was not able to solve them in contest,for one hour i was struggling to find the mistake i made,i found the mistake in b but was not able to find in problem c

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

can someone please tell we why this approach is wrong for C problem. ~~~~~ 358167776

~~~~~

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

For problem F, the problem statement says:

"You choose any vertex of the tree v (including the root or a leaf) and "shake" it. After that, cherries fall from all the leaves that are descendants‡ of vertex v (if vertex v itself is a leaf, then a cherry falls from it). If cherries have already fallen from any leaf before, the tree will break, so such a situation must be avoided."

And it identifies "Descendants of vertex v" as follow:

"‡The descendants of vertex v are all vertices u≠v such that on the shortest path from the root to u, vertex v is encountered."

Which I guess it is obvious enough (at-least for me & that I'm not missing anything) that if I for example choose any node to shake: then I can't shake it again or any other node below it. Why? because from my understanding if I shake a node then all cherries in its children will fall, if I then shake it again or any other node below it, it will also affect the leaves and the rule "If cherries have already fallen from any leaf before, the tree will break, so such a situation must be avoided." would apply. However in the editorial of the analytical solution for F, it claims that I should initially shake the root node, then I can shake anything I want as long as it's not a leaf, how so? Shouldn't the rule still apply?

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

in problem G, how does the segment tree descent work, can someone explain

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

I would like to clarify regarding the similarity flag on my submission.

I solved the problem independently during the contest. My approach was based on modeling the tree using a DFS and maintaining a bitmask representing possible values modulo 3 from each subtree. For each child, I merged masks by combining possible residues and updating the current node’s mask. Leaf nodes returned the base mask, and finally I checked whether residue 0 was achievable at the root.

I did not share my code, discuss implementation during the contest, or use any public code-hosting or collaborative platform. The similarity may be because this problem leads to a very standard tree-DP-with-bitmask approach, where transition logic and structure naturally become similar across solutions.

I respect Codeforces rules and am willing to provide any clarification if needed.

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

Another approach for problem F.

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

How do you solve the bonus for D..

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

E was such a beautiful Problem..

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

In problem c according to the given solution, if we give next iteration just a odd number then also it will work.

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

i got goomba stomped in virtual ;-;

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

Problem E is really nice! I first tried using a difference array plus a monotonic queue to track the minimum difference, but it bombed — O(n²) time complexity, got TLE on test case 7 straight up. So I switched things up: still stuck with the difference array, but swapped the monotonic queue for a monotonic stack to keep track of the maximum valid interval length. After that, the inclusion-exclusion principle made it a piece of cake, and it’s O(n) time overall. Here’s my submission if anyone wants to check it out: 363405796

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

There's also an alternative solution to F that i found which is quite elegant. Instead of working top-down, imagine we start by just choosing to shake all the leaves in the tree. Let L be the total number of leaves. If L mod 3 is 0, we can just choose all the leaves and the answer is yes. If L mod 3 is not 0, we need to adjust our chosen set by picking a parent vertex instead of its leaf descendants, which removes S leaves (where S is the number of leaves in that subtree) and adds 1 parent vertex, making the net change in our chosen count exactly 1 minus S. If our initial L mod 3 is 1, we need an overall change of 2 mod 3 (or -1), which means we either have to find one vertex where the number of leaves in its subtree is 2 mod 3 (since 1 minus 2 is -1), or find a pair of disjoint vertices that each have 0 mod 3 leaves (since 1 minus 0 plus 1 minus 0 is 2). Conversely, if L mod 3 is 2, we need an overall change of 1 mod 3, so we just find 1 vertex with 0 mod 3 leaves (since 1 minus 0 is 1), or find 1 pair of disjoint vertices that each have 2 mod 3 leaves (since 1 minus 2 plus 1 minus 2 is -2, which is equivalent to 1 mod 3). It works out every time, and you cant have more than 2 subtrees to change parities because adding three of the same modulo changes would just add up to a multiple of 3 and cancel each other out, meaning it always strictly reduces to one of these exact cases.

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MXN = 200000+10;
ll total[MXN];
ll dfs(ll node, ll p, vector<vector<ll>> &adj){
    for(auto &v: adj[node]){
        if(v!=p){
            total[node] += dfs(v,node,adj);
        }
    }
    if(!total[node]) total[node] = 1;
    return total[node];
}
bool dfs2(ll node, ll p, vector<vector<ll>> &adj, ll mod, ll &cnt, bool &ok){
    ll curr = cnt;
    for(auto &v: adj[node]){
        if(v!=p){
            bool check = dfs2(v,node,adj,mod,cnt,ok);
            if(check && curr) ok = true;
            curr = cnt;
        }
    }   
    if(ok) return true;
    if(total[node]%3==mod){
        cnt++;
        return true;
    }
    return false;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll tt;
    cin >> tt;
    while(tt--){
        ll n;
        cin >> n;
        for(int i = 0; i <= n; i++) total[i] = 0;
        vector<vector<ll>> adj(n+1);
        for(int i = 0; i < n-1; i++){
            ll u,v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        dfs(1,0,adj);
        vector<ll> children(n+1);
        ll have = total[1];
        if(have%3==0){
            cout << "YES" << endl;
        }else{
            bool done = false;
            if(have%3==2){
                bool ok = false;
                for(int i = 1; i<= n; i++){
                    if(total[i]%3==0) done = true;
                }
                ll cnt = 0;
                dfs2(1,0,adj,2,cnt,ok);
                if(ok||done){
                    cout << "YES" << endl;
                }else{
                    cout << "NO" << endl;
                }
            }else{
                bool ok = false;
                for(int i = 1; i<= n; i++){
                    if(total[i]%3==2) done = true;
                }
                ll cnt = 0;
                dfs2(1,0,adj,0,cnt,ok);
                if(ok||done){
                    cout << "YES" << endl;
                }else{
                    cout << "NO" << endl;
                }
            }
        }
    }
}
»
3 недели назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

i think it is a good contest. but C is 1300(

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

I can't understand how the descent on the segment tree in G works. It involves the minimum number in a given segment. Could anyone help me?