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

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

Спасибо за участие в раунде! Мы надеемся, что вам понравились задачи. Нам очень жаль, что с условием в задаче B возникли проблемы.

Фан факты

2189A - Таблица, а в ней числа

Идея: Fakewave

Решение
Код
Оцените задачу

2189B - Проклятие лягушки

Идея: furt1ve, Fakewave

Решение
Код
Оцените задачу

2189C1 - XOR-удобство (простая версия)

Идея: Fakewave

Решение
Код
Оцените задачу

2189C2 - XOR-удобство (сложная версия)

Решение
Код
Оцените задачу

2189D1 - Маленькая строчка (простая версия)

Идея: Fakewave, yanb0

Решение
Код
Оцените задачу

2189D2 - Маленькая строчка (сложная версия)

Решение
Код
Оцените задачу

2189E - Большинство побеждает?

Идея: Fakewave, furt1ve

Решение
Код
Оцените задачу

2189F - Жора-Пылесос

Идея: yanb0

Решение
Код
Оцените задачу
Разбор задач Codeforces Round 1075 (Div. 2)
  • Проголосовать: нравится
  • +92
  • Проголосовать: не нравится

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

Автокомментарий: текст был обновлен пользователем Fakewave (предыдущая версия, новая версия, сравнить).

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

thanks for the fast editorial

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

First

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

Автокомментарий: текст был обновлен пользователем yanb0 (предыдущая версия, новая версия, сравнить).

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

Great contest C2 and A made me cry

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

C1, C2 good problems.. B was so greedy... I think A is better than B A was interesting

D1 was easy Should try more.

if (s[i] is 1) ans *= 2; else ans *= i — 1;

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

B statement was too rubbish !!!

This change later --> bith , 2*bith ,..

that made things actually clear

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

Was B easier than A?

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

Nice problems, english could be better. Would be better if it was 2.5 hrs.

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

Great contest! Explanation given in questions could have been better.

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

Thanks for the contest. It was hard, i was stuck on A for two hours, felt like i should be able to solve at least A. I mean its supposed to be the easiest. After reading the fun fact, it made me think juts how much I need to practice more.

Ps: Someone plz confirm if this contest was really authored by high school students, i mean damn!

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

    same here bro I couldn't even solve A during contest but somehow I managed to solve B 30 min before contest end. Happy to know many people felt the same. Now I am more pumped to practice more.

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

      I consider A is not so hard.I made it in 30 minutes and got ac for the first submission.But i was stuck in B and C for 1 hour.I saw the Tutorial after the contest and now i think B is easy indeed,but i was so stupid.

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

        Yep B was easy but difficult to understand I suppose. Although I couldn't spend time on C1 bcz my morale just broke in start as I couldn't solve A and was finding B to be difficult to understand.And yes A is ezy now as I read its tutorial but I never got the intuition for it during contest.

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

        tbh, when i saw the editorial it still didn't made full sense, but the logic they used was just amazing, i mean its something simple, and a logical but it just didn't hit me at that time. i was handling the complexity of how to count numbers less than h and l without duplicates and so.

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

      yeah i mean the sheer demotivation of not solving A was too much for me, I never used so much brain on A, though it feels good to know i have to work on.

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

    it make sense that this contest was made by high school student.I know a student who learnt c plus plus in middle school.

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

This is some text.

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        cout << 1 << " ";
        for (int i = 2; i <= n - 1; ++i)
        {
            cout << (i ^ 1) << " ";
        }
        if ((n - 1) % 2 == 0)
        {
            cout << n - 1 << " ";
        }
        else
        {
            cout << n << " ";
        }

        cout << endl;
    }
    return 0;
}

The rest of the text. I don't know why I can pass just by swapping the first and last numbers in the output.

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

My first contest, unable to solve C2. Hope I can get better next time.

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

Maybe D1 is not so complex?

Maybe you can compute answer modulo c and check if it is 0 like this?

Sorry for my bad english :(

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

I used a two pointer approach to solve A https://mirror.codeforces.com/contest/2189/submission/359430375 ~~~~~ #include <bits/stdc++.h> using namespace std;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    //clock_t tStart = clock();
    int T; cin>>T;
    while(T-- > 0) {
       int n, l, h; cin>>n>>h>>l;
       vector<int> v(n);
       for(auto &num : v) cin>>num;
       sort(v.begin(), v.end());
       int mx = max(l, h);
       int mn = min(l, h);
       int left = 0, right = n-1;
       int res = 0;
       while(left < right) {
         if(v[left] > mn) break;
         if(v[right] > mx) {
          right--; continue;
         }
         res++;
         left++; right--;
       }
       cout<<res<<'\n';
    }
    //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}

~~~~~

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

    Yes, I also used two pointers for problem A : 359421026

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

      // i think this is an easier approach ~~~~~~~~~~~~~~~~~ void solve(){

      ll n, h, l;
      cin >> n >> h >> l;
      ll x = min(h,l), y = max(h,l);
      ll a[n], small=0, big =0;
      for(ll i=0; i<n; i++){
          cin >> a[i];
          if(a[i]<=x )small++;
          else if(a[i]<=y)big++;
      }
      if(small >= big){cout << (small+big)/2 << endl;}
      else{cout << small << endl;}

      } ~~~~~~~~~~~

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

        i see you are first counting the smaller elements in the array, and if they are not small, you check if they are bigger or not, so you have count of all elements smaller than h, and all elements smaller than l excluding elements from h count, so wouldn't the straightforward way will be min(small,big), because i am not getting the logic in this line if(small >= big){cout << (small+big)/2 << endl;}.

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

    Yeah, same two pointers -

        int n,h,l;
        cin>>n>>l>>h;
        vector<int>arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr.begin(),arr.end());
        int cnt=0;
        int i=0,j=n-1;
        while(i<j){
            int x=arr[i];
            int y=arr[j];
            if(max(x,y)<=max(h,l) && min(x,y)<=min(l,h)){
                cnt++;
                i++;
                j--;
            }
            else{j--;}
        }
        cout<<cnt<<endl;
    
»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

B>C I did the question C by observing a pattern for the even and the odd numbers though i did C after the contest ,But B was a nightmare for me in the contest i couldn't even understood it for the first 30 minutes and eventually leaved it as it is.

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

Can Anybody Explain the last part of my code, initial part i have written in the observation part but after that i am little bit confused in the ceil of (x-pos) part, I will be grateful for your help.

My Submission

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

    If you need to travel 4 units of distance and your best operation is (2,2,1) then you will travel 3 units per cycle , so to cover 4 units you will require 2 cycles , one with 3 units and the other with 1 unit to reach the target.

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

I've done a unbelievable weird job during this round

solved 6 but ranked 850+

because of 10+ penalties

I suspect I'm not a human being

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

Can someone explain c2 ? printing -1 approach is cleared, just explain how to generate all numbers.

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

An intuitive way to approach problem C2 after C1 is to observe n = odd works as it is, n = power of 2 will lead to generating values greater than n, hence not possible. For n even, keeping the C1's solution intact and just swapping the first value with another will work, maintain a set for the same.

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

I could be the only person to solve A with two pointers ~~~~~ 359372727 ~~~~~

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

how will we solve the A question if it said, any cell can be chosen maximum one time? can anybody help me with the solution pls

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

Problem A was easy but problem B was way more tough or the language of the question was not clear , i don't know

Totally a pretty tough contest

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

Problem E, I came up with the conclusion for the case where the number of operations ≤ 4, but how can one come up with the necessary and sufficient conditions for k = 2 and k = 3?

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

    You can look at cases which operations could have been applied and come up with sufficient and necessary conditions for those cases.

    If $$$k = 2$$$, then some operation $$$[l, r]$$$ was applied after which the operation was applied on the whole string. Suppose that the majority value in $$$[l, r]$$$ was 1. Then we can show that we could have finished in one operation. Therefore the majority value in $$$[l, r]$$$ must have been 0. Let $$$z$$$ / $$$o$$$ be the number of zeroes / ones outside $$$[l, r]$$$, respectively. Then $$$z + 1 \leq o$$$ or in other words $$$z \lt o$$$, since we finished in one operation after applying $$$[l, r]$$$. From here you can show that either prefix before $$$l$$$ or suffix after $$$r$$$ has strictly more ones than zeroes. Similarly, with this condition on prefix/suffix you can show that you can finish in 2 operations. Hence, these are sufficient and necessary.

    If $$$k = 3$$$, two operations $$$[l_1, r_1]$$$ and $$$[l_2, r_2]$$$ applied before finishing with operation on the whole string. Let $$$[l_2, r_2]$$$ represent the range applied in the second operation corresponding to the range from the initial string. We can consider two cases here:

    • If $$$[l_1, r_1]$$$ and $$$[l_2, r_2]$$$ intersect, then we could have taken the union of the ranges instead as one operation and finished in 2 operations instead. We can show this by considering the cases of majority values in these ranges.

    • If $$$r_1 \lt l_2$$$ (i.e. ranges do not intersect), then with the similar argument as above, if at least one of the operations had 1 as majority, we could have finished in 2 operations. Hence, 0 was the majority value in $$$[l_1, r_1]$$$ and $$$[l_2, r_2]$$$. Let $$$z_l$$$, $$$z_m$$$, $$$z_r$$$ denote the number of zeroes in ranges $$$[1, l_1 - 1]$$$, $$$[r_1 + 1, l_2 - 1]$$$ and $$$[r_2 + 1, n]$$$ respectively. Similarly, let $$$o_l$$$, $$$o_m$$$, and $$$o_r$$$ denote number of ones in the same ranges. Then $$$z_l + z_m + z_r + 2 \leq o_l + o_m + o_r$$$. Which means that either $$$o_m \geq z_m + 2$$$ or $$$o_l \geq z_l$$$ or $$$o_r \geq z_r$$$. Since we can show that if these conditions hold we can finish in 3 operations, just by removing one of the operations from case with 4 operations, we have showed that these are necessary and sufficient conditions.

    Hope it helped. Feel free to ask any questions if some parts are unclear.

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

      In the case of $$$[l_1, r_1]$$$ and $$$[l_2, r_2]$$$ intersecting for the case $$$k = 3$$$, the idea that we could have finished in 2 operations by taking the union is not correct. Thanks to xyzt8988998 for reaching out with the mistake. The right claim is:

      Claim: If the ranges intersect then there is either a prefix or a suffix that has as many 1 as 0.

      First of all, since after applying $$$[l_1, r_2]$$$ the range is compressed into one element, if $$$[l_1, r_1]$$$ and $$$[l_2, r_2]$$$ intersect, then $$$l_2 \leq l_1$$$ and $$$r_1 \leq r_2$$$.

      • If $$$l_2 \gt 1$$$ and $$$r_2 \lt n$$$ then either the prefix $$$[1, l_2 - 1]$$$ or the suffix $$$[r_2 + 1, n]$$$ has as many 1s as 0s. Otherwise, no matter what would be the majority value in $$$[l_2, r_2]$$$, the third operation will have strictly less 1s then 0s and we could not have finished in 3 operations.
      • If $$$l_2 = 1$$$ or $$$r_2 = n$$$, without loss of generality, let's assume that $$$l_2 = 1$$$. When $$$r_2 = n$$$, the same arguments can be applied just by reversing the string. If (after applying operation $$$[l_1, r_1]$$$) the majority element in $$$[1, r_2]$$$ is 0, suffix $$$[r_2 + 1, n]$$$ has strictly more 1 then 0, since we finished in 3 operations. However, then we could have completed this case in 2 operations instead. Hence, $$$[1, r_2]$$$ has majority value as 1 (after applying $$$[l_1, r_1]$$$). Also, observe that since we finished in one operation after applying $$$[l_2, r_2]$$$ and it had 1 as majority value, let $$$x$$$ be the number of 0s in the range $$$[r_2 + 1, n]$$$ then the number of 1s in the range is at least $$$x - 1$$$.
        • If the majority element in $$$[l_1, r_1]$$$ is 1, then the majority element in $$$[1, r_2]$$$ is 1 (in the initial string). Our claim in met.
        • If the majority element in $$$[l_1, r_1]$$$ is 0, then again either the prefix $$$[1, l_1 - 1]$$$ or range $$$[r_1 + 1, r_2]$$$ has strictly more 1 than 0.
          • The first case can not happen, from the same thought process as above.
          • The second case, when the range $$$[r_1 + 1, r_2]$$$ has strictly more 1 than 0, let y be the number of 1s. Then number of 0s is at most (y — 1). Then the number of 1s in $$$[r_1 + 1, n]$$$ is at least $$$y + x - 1$$$ and number of 0s in $$$[r_1 + 1, n]$$$ is at most $$$x + y - 1$$$. Therefore, the suffix $$$[r_1 + 1, n]$$$ has as many 1s as 0s. Our claim is met again.
»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

B: ceil == wa case 9 No ceil == acepted

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

The problem statement is almost bullshit

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

I understood the problem B during contest in just one read through and still couldnt solve it lol Im wondering what the rating of problem B will be

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

Hey everyone!

I’ve prepared detailed articles for Problem A and Problem B, explained in both English and Hinglish to make them super easy to follow.

What makes these articles useful?

Simple, beginner friendly language

  • Starts with understanding the problem clearly

  • Builds intuition step by step

  • Derives the formula logically

  • Provides a code template so you can try coding on your own

  • Ends with the complete solution for verification

The goal is not just to solve the problem, but to learn how to think and approach similar problems in the future.

Check them out here:

Problem A: - https://www.xorthax.com/codeforces-articles/round-1075-div-2-problem-a

Problem B: - https://www.xorthax.com/codeforces-articles/round-1075-div-2-problem-b

I genuinely hope you find these helpful. Do give them a read and let me know your feedback!

If you want more articles like this, do comment below.

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

A was easy, solved it pretty fast. However, it took me quite a lot of time to think about B. Therefore, I have no time left to think about C, and I'm kinda sleepy too cuz it's late at night in my country. Anyways, I did improve, cuz in the past I only solved A.

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

About D1, you can reconcile the idea and the code like this: the real constraint isn’t simply “you can’t insert in the middle,” but that any insertion must not break an already satisfied prefix w condition (mex = k). The loop from i = 0 to n − 2 is effectively counting how many insertion positions are safe before the first position where inserting would destroy the existing prefix property. When m = 1, a full segment with mex = k must remain intact, so only the two ends work; when m = 0, as long as the prefix hasn’t reached mex = k yet, inserting won’t affect it, giving i valid positions. From this perspective, the code is implicitly checking the previous w-state rather than explicitly reasoning about “middle vs ends,” so the implementation and the intended logic do line up—just from different angles.

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

The editorial for problem F seems too overwhelming. Is this normal, or is there something wrong with me? Also, is there any easier approach?

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

can anyone tell me how someone can get an intuition on C1?

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

great contest and editorial

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

D1: Need some help with the intuition for the solution

I understand these conditions and got them myself: • If s[i] = 1, then the value i must be placed entirely to the left or entirely to the right of all values 0..i−1. • If s[i] = 0, then the value i must be placed strictly between the values 0..i−1

I’m confused about the leap from these conditions to the construction. In particular, I don’t understand why constructing the permutation from 0 upward works, nor how one is supposed to come up with this idea during the contest. "Let's construct p, starting with p=[0] and sequentially inserting the numbers 1,2,…,n−1 into some positions." <- how do you get to this idea when solving yourself.

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

I think I have a simpler solution for F, correct me if it's the same as in the editorial. However I don't have a proof for it, though there is some intuition.

I have two claims. First — we need to do operations in at most one vertex. Maybe it's provable from the facts in the editorial, but idk. Before the second claim we need to understand some properties. Suppose the tree is rooted at the vertex $$$r$$$ and we look at the subtree of vertex $$$v \neq r$$$. Let $$$s_v$$$ be the sum of all $$$a_u$$$ in the subtree. Then after applying the operation the number of nuts in the subtree is $$$\max(s_v - 1, 0)$$$. From this fact it can be shown, that if we apply at least one operation, then we need to do at least $$$s_v$$$ to get rid of the nuts in vertex $$$v$$$ in 2 cases:

  1. $$$a_v \ge 0$$$ and there is at least one non-negative $$$a_u$$$ in the subtree.

  2. $$$a_v = 0$$$ and there is at least two non-negative $$$a_u$$$ in the subtree.

So there are $$$O(n)$$$ "events" which change the number of distinct vertices after operations among all roots (it's basically all possible values of $$$s_v$$$).

Let's find all these events. Now the plan is to bruteforce every possible root and find the optimal answer for each one. To bruteforce roots we'll do rerooting and to find the minimum among $$$O(n)$$$ values fast we'll use segment tree. Let $$$c_i$$$ be the i-th unique value in the sorted array of events. Initially the answer for $$$c_i$$$ operations is $$$c_i \cdot p$$$ plus the number of vertices with nuts. Vertex $$$v \neq root$$$ contributes $$$q$$$ to every $$$c_i \lt s_v$$$, so we add $$$q$$$ on a prefix.

Then if we reroot from $$$v$$$ to its child $$$u$$$, only their $$$s$$$ and number of non-empty children subtrees change, so we can update this information and do certain additions (and subtractions) in the segment tree. This part is technical so instead of writing in detail I'll just give my submission 362825458.

Time complexity $$$O(n \log n)$$$ memory $$$O(n)$$$.

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

A made think a lot. Not expected this easy solution

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

Can someone explain why for B, you would commit to one jump type immediately? It seems to me you could travel t = sum(a_i(b_i — 1) for all i) at the beginning. Essentially you travel as much distance as possible using each jump type before incurring a penalty (rollback). Only after do you commit to one jump type, this doesn't seem disallowed to me by the problem statement. I have a submitted solution using this solution which passed all testcases. This appears to give strictly more distance than committing to one type from the beginning.Is there a constraint or reasoning I’m missing that makes combining moves like this suboptimal or invalid?