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

Автор doreshnikov, история, 5 лет назад, По-русски

Всем привет!

Приглашаем Вас принять участие в Codeforces Round 744 (Div. 3) – раунд для третьего дивизиона, который состоится во 28.09.2021 17:35 (Московское время). Раунд был составлен совместными усилиями меня и MikeMirzayanov, и мы очень надеемся, что задачи вам понравятся и покажутся достаточно интересными.

Отдельно хочется поблагодарить MikeMirzayanov за помощь как в составлении, так и в разработке задач для раунда. Это второй Div. 3 раунд, в создании которого я принимаю участие, но только первый, в котором я готовлю задачи полностью, так что без его руководства я бы потратил на это гораздо больше времени.

Помимо этого отдельная благодарность nizamoff, andreumat, QAZZY, Vladosiya, CtrlAlt, vladmart, Igorjan94, okwedook, ashmelev и Aris за тестирование раунда и фидбек по задачам, а также Gassa и geranazavr555 за вычитку и корректировку условий – благодаря вам этот раунд стал заметно лучше, чем мог бы быть без вашего вклада. Ну и наконец, спасибо всем, кто примет участие в раунде! Раунд будет содержать от 7 до 8 задач и расчитан по сложности на участников с рейтингами до 1600, однако все желающие с рейтингом 1600 и выше могут зарегистрироваться на раунд вне конкурса.

Раунд пройдет по правилам образовательных раундов. Таким образом, во время раунда задачи будут тестироваться на предварительных тестах, а после раунда будет 12-часовая фаза открытых взломов. Мы постарались сделать сильные тесты, что, однако, не гарантирует, что фаза взломов будет безрезультатной.

Вам будет предложено 7-8 задач и 2 часа 15 минут на их решение. Штраф за неверную попытку в этом раунде (и последующих Div. 3 раундах) будет равняться 10 минутам.

Напоминаем, что в таблицу официальных результатов попадут только достоверные участники третьего дивизиона. Как написано по ссылке – это вынужденная мера для борьбы с неспортивным поведением. Для квалификации в качестве достоверного участника третьего дивизиона надо:

  • принять участие не менее чем в двух рейтинговых раундах (и решить в каждом из них хотя бы одну задачу)
  • не иметь в рейтинге точку 1900 или выше.

Независимо от того, являетесь вы достоверными участниками третьего дивизиона или нет, если ваш рейтинг менее 1600, то раунд для вас будет рейтинговым.

Всем хорошего настроения и удачи!

UPD: Выложен разбор задач!

  • Проголосовать: нравится
  • +308
  • Проголосовать: не нравится

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

Is there a way to become a tester if there is no communication with codeforces admins?

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

My first unrated round.

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

i hope to be specialist after this round ..

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

It may be a rare 8-problems div 3 round!

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

OH MY GOD! I can't wait for this div 3 contest! I heckin' love div 3 contests!

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

As a contestant, I hope the time complexity of me becoming an expert is $$$O(1)$$$.

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

Will a non-trusted participant be rated? New one here can not be trusted.

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

Just failed School's selection round for NOI.

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

    Just relax and keep going.I really admire that you have the opportunity to participate in information competition in the stage of middle school. The future will be full of light and hope,Just keep going. I believe as long as you persist on learning programming, u can become the person u want. No matter NOIP first level, or NOI gold medal,u still have the opportunity,u still have the hope and energy!!!!!

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

This is one of most awaited contest for me , a week without contest on codeforces is hard :( .

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

I hope I can become blue after this round.

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

honestly, many of us was waiting for this round, thanks

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

Very nice! Looking forward to my first rated round

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

I wish that i become Specialist after this round. Upvote for best wishes. Thanks and Good luck to all.

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

A round after more than a week. Wish ya'll the best of luck.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится
lighthearted meme
»
5 лет назад, скрыть # |
 
Проголосовать: нравится -24 Проголосовать: не нравится

Always better to participate in contest instead chatting with gf. Hahaha

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

Will this round be easier than the last Div.3 contest?

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

I am on a streak lately, I became 5* on Codechef few days back and qualified for hackercup T-shirt too, I hope my streak continues!

Wish Me Luck!

UPD: Didn't do very good but since I avoided negative delta so I think the streak is still on.

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

Loved the gradual increase in difficulty in the last contest conducted by +doreshnikov , hope to see a simillar round today!

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

There is too much of a difficulty gap b/w A and B !! B is not at all a regular Div.3 B problem.

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

implementationforces

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

Sorry to bother folks who are participating in today's round, but today's round requires a serious plag check, problem B had a sudden surge in submissions from 3K to 7K in just 5 minutes. Like seriously? I don't think B was an easy one to solve for most folks below the 1300 rating (I got it right after like 5-6 attempts).

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

While Polycarp is on vacation Casimir is taking over.

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

Today's round had nice problems (especially F and G). Thanks to MikeMirzayanov for amazing m2.codeforces.com platform (I had connection problems and the lightweight version was very useful). :D

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

Enjoyed this round. Especially E2.

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

Holly… Amazing div. 3 round! Btw. anyone knows why cf-predictor is down?

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

How to solve E2 ?

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

    Suppose l_i is the increase in the number of inversions if you add i_th element to the beginning and r_i is the increase in the number of inversions if you add i_th element to the end.

    It's easy to observe that neither of l_i or r_i depend on the order of first i-1 elements. So, just add min(l_i,r_i) to the answer at each step.

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

    For E2, first apply coordinate compression.

    Then, using a segment tree/binary index tree, calculate whether prepending or appending the element is better. It's better to prepend the element whenever there are more processed things greater than the current element. Better to append the element whenever there are more processed things less than the current element.

    130179241

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

      It's better to prepend the element whenever there are more processed things greater than the current element. Better to append the element whenever there are more processed things less than the current element.

      Is there a proof for this process working greedily? I mean wouldn't the answer change for the (i+1)th element change depending on where the ith element is placed? A bit confused over this intuition. (The position of the ith element may add to the inversion count of the (i+1)th element)

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

        Not really, the ith element can only be either added to the beginning or the end, so the only thing that matters is among the first (i-1)th numbers,how many numbers are smaller than the ith number if you are adding it to the beginning, and how many numbers are greater than the ith number if you are adding it to the end.

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

    You can also solve it using:

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

Is there a way faster than nlogn for E2? I was so happy when i came up with a multiset, but it still TLE

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

Loved the contest, The Problem D on this contest is similar to a previous Div 3 round D problem.

Link to the similar problem : https://mirror.codeforces.com/contest/1506/problem/D

I request everyone , who read the problem D or solved it to go through it also once.

The concept required to solve both the problems are similar.

It is such a nice question on the application of Heaps(Priority Queues).

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

Good round. BTW, how to solve G?

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

Did I just participate in a div-2 round?

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

What would be problem rating of E1 ? 800 ?

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

why nlogn solution give TLE on E2?

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

where to access the editorials of #744 (Div.3)?

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

Great round. But I would have appreciated some drawings in G, as in C.

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

RIP my rating . I was trying right shift in problem B :')

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

I didn't able to solve any question By the way I try solve the first question but unable

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

As I remember, Problem D was already used in past contests with different statement but same idea

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

It would have been better if F had integers upto $$$10^9$$$ instead of 0's and 1's .

The problem would have been similar to this and we would have to just process Range AND Queries on individual components

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

My reaction seeing that the guy name was Casimir:

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

The problems were literally all over the place.
Even deciding which ones to solve was more difficult than E1.

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

How to solve G? something like dp?

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

Can someone elaborate the problem C please, still I can't understand what it wants!!

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

THE EASIEST E1 EVER! :)

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

Can someone help me to figure out the mistake with my logic/code for problem E2?(thanks in advance)

Logic: During each insertion, let the current element be K, we add min(number of elements strictly lower than K, number of elements strictly greater than K) to the answer. I implemented this using PBDS multiset.

my submission

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

T~T,It was another very violent topic, and then I saw that I finished it in three minutes, but I felt good on the whole

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

How to solve G?

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

A to F easy solutions with Code and Explanations Happy Coding.

A
B
C
D
E1
E2
F
  • »
    »
    5 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    @Fawkes For problem 2 (B) the problem statement mentions: Any sorting method where the number of shifts does not exceed n will be accepted. `` So did this mean that when we take one interval i.e from I to n (like in your soln) we can only shift max n times or did it mean that the total number of shifts shouldn't exceed n?

    because if we take the example: 5 4 3 2 1 then for I = 0, we shift 4 times, and then I = 1 we shift 3 times so the total would exceed n, no?

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

    what is the reason to decrease two big values by only one can not it be decreamented by minimum of these .I mean to say min(i1[0],i2[0]). why does not this process give best answer

    while(pq.size()>=2)
      {
        pair<ll,ll>pp1=pq.top();
        pq.pop();
        pair<ll,ll>pp2=pq.top();
        pq.pop();
        v=min(pp1.ff,pp2.ff);
        c+=v;
        if(v>0)
        ans.pb(mpr(pp1.ss,mpr(pp2.ss,v)));
        pp1.ff-=v;
        pp2.ff-=v;
        if(pp1.ff>0)
            pq.push(pp1);
        if(pp2.ff>0)
            pq.push(pp2);
      }
    • »
      »
      »
      5 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Imagine three people with times: 6 6 2.

      You would answer 6, since you would pick both persons with a = 6. But the real answer is 7, those two people with a = 6 should talk with each other 5 times, and the last person should talk to both of them separatelly.

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

Why am I not able to hack any solution or even been able to lock any problem during Codeforces Round #744 (Div. 3) ?

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

Nice round, with great problems.

Although the order of problems could be better, the problems were great!

Thanks :)

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

Most unbalanced div $$$3$$$ round ever :(

The difficulty was like $$$A \lt E1 \lt B \lt D \lt C$$$ as I felt.

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

In problem F, I have used the fact that once some a[index] becomes 0, it will always remain 0 and will turn a[(index+d)%n] to 0 as well..

So, at each step if there's no new index where 0 is formed.. ans will be -1, else we can store these new indices to use them in the next step till all indices are converted 0.

So, if at each step "X" new indices are formed.. the process will go on for N/X iterations .. making it X*(N/X)

I am not pretty sure about this complexity and method.. Can someone provide a counter case/hack it, or affirm it ?

Submission

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

Who made these test cases? E1 hacks are going insane with very straightforward hack.

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

The downfall of E1...

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

Can someone explain approach for C plase

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

    Try to find potentional center cells,say {x,y} and calculate the minimum of its left and right arms, say d. If d>=k, add a tick in another grid of size d at {x,y}. After you have done this for all potential center cells, check whether the original grid and the grid you made are same or not. My solution:130153692

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

B submission WA I was trying to solve be for more than 1 hour but it was still giving the wrong answer. The codeforces engine was giving a different answer and my machine was giving different. Mine was correct. I later submitted the problem with very minor change and it got accepted. It was some undefined behaviour I guess, if anybody could explain why that happened, I would be really grateful. Accepted Solution

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

please take a look into hack #758216, the result is "unexpected verdict".
(I mistakenly submit invalid input, then I got such result. Maybe the validator of G is wrong.)

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

I have tried a video solution for the problem F: https://www.youtube.com/watch?v=8qC3qyQsE8s Hope it will help you if you need it.

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

Hi any one could help me to solve problem D, give me the idea or full code, this is my code i got WA, cause their is no tutorial, thanks in advance, and sorry for my English. void solve() {
int t; cin >>t; while(t--) { int n; cin >>n; vii v(n); lp(i, n) { cin >>v[i].f; v[i].s = i+1; } sort(v.rbegin(), v.rend()); vii ans; int i=0, j=1; while(v[i].f&&v[j].f) { ans.pb({v[i].s, v[j].s}); v[i].f--; v[j].f--; for(int a=j;a+1<n && v[a].f < v[a+1].f; a++) swap(v[a], v[a+1]); for(int a=i;a+1<n && v[a].f < v[a+1].f; a++) swap(v[a], v[a+1]);

}
    cout <<sz(ans)<<"\n";
    rep(i, ans) {
        cout <<ans[i].f<<" "<<ans[i].s<<"\n";
    }
}

}

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

    When posting your code, try to include them in spoiler and block tags, so that they maintain their indentation. As for D, the basic idea is to use a max heap, (priority_queue in C++). The idea is to take two indices with the maximum sociability every time and have them meet each other. Their sociability decreases by one everytime, so, you decrease that and if their sociability is still greater than 0, push them back into the max-heap.

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

      can you please explain as to why letting two with the max sociability meet each other would result in maximum no. of meetings ?

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

        We would want to make sure that the number of meetings is the maximum. Taking the indices which currently have the maximum sociability does this, because everytime, we are decreasing the sociability, so the indices that have maximum sociability changes after a point of time, which means meetings are scheduled as long as they are possible. Let us take a counter-example: say, A={1, 2, 3}. Now, if we considered the indices with the minimum sociabilty, we will be able to schedule only two meetings-> (0-1) and (1-2). On the other hand, if we considered indices with the maximum sociability everytime, we will be able to schedule 3 meetings-> (2-1), (2- 1) and (2-0).

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

Хорошие системные тесты для задачи E1 :)

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

I would like to report a system bug in problem G.

When I submit my solution, it gets time limit exceeded at test set 22. But when I looked at test set 22, it have three test cases, and first one array length is 10000. But problems says the total number of G does not exceed 10000, so it is not a valid test set.

I look at others solutions passed during contest, and the total number is 18. So test set 22 is not generated by authors, but by hackers after the contest.

Then I tried to generate an invalid test set (3 test cases with total number of n 30000) and hacked others code (I only hacked people who are not officially participate the contest), they all succeed.

Therefore, please remove these test sets that sum of the n > 10000, and rejudge these hacked solutions for problem G. It is unfair for participated who solved problem G but exe time is larger than 333ms.

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

It's rare to see something like this : same same same same same same same same same same same same same same same ....... code.

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

Thnx for great round, even though I wasn't so luky. Anyway I may have misunderstood problem B, I used Bubble sort considering swaps as d = 1 circular shifts, on paper it all make sence but yet it get me wrong answer on test 2. this is my submission 130155379 , could any good one of you help me with it ?

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

    Swapping adjacent elements is not an efficient way of sorting the array.

    To go straight to the point, the maximum number of operations/shifts your program could need is $$$\frac{n(n-1)}{2}$$$ when the the array is in the form $$$a_1 \gt a_2 \gt \dots \gt a_n$$$.

    By the way the number of such swaps needed to sort the array is the same as the number of inversions in the array if you want to look into that.

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

I'm new here, so the round should be rated for me but, the contest is showing itself in the unrated section in my profile contests, also I'm not in the standings. I did solve 4 questions during the contest. Can anyone tell me what's this issue?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
C was more difficult than D according to me. I ended up using most of the time to solve C. It just got stuck in my head. E1 was a joke. 

Lesson: READ. READ ALL PROBLEMS.

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

What is invalid test in Hacking? I have also used endl but dtill getting this error?

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

Could anyone please help me understand why I got TLE in E2? I used Fenwick tree + coordinate compression, so this should be O(nlogn) but somehow it fails in testcase #18.

My attempt from the contest (or slightly modified version that's easier to read).

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

I think E1 is more suitable for the difficulty of B than the actual B...

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

Hi !

is there any one who can help me with this ?

in problem B , the first test ,my output to testcase 3 is : 2 : 1 3 2 — 3 4 1 but is gives me a WA : wrong answer Element a[0] = 4 is greater than element a[1] = 1 (test case 3)

but its not logical ! if you shift the elements in the way that I said , the array will be sorted !

can you find my mistake ? my submission : 130240370

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

I have solved four questions in this contest and having rank between 2500-3000, but now they are saying that I have copied the solution of the problem, but I haven't. I am coding in ideone.com, is there any problem with it. I thought after this I will have a 1300+ rating. please help, how will I convince that I do not copy any solution...

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

In D, the most common solution that I have come across involves heaps and priority queues. However, in my initial approach I used DP by modelling the problem as the 0-1 Knapsack Problem. I 1st calculated the sum of the sociability of all the people in a test case, and since each talk would require the sociability of both the participants to decrease by 1, the maximum possible talks in a meeting is (sum of sociability)/2 Therefore, the size of the knapsack can be set equal to (sum of sociability)/2 and the weights set and the values set will be the same, i.e., the input array of sociability of each person. Therefore, by finding the maximum weight that can fit inside the knapsack, we can maximise the number of talks in the meeting. However, my solution fails on the 69th test case of the 2nd test set. Here is my submission. I would appreciate any help in pointing out the flaws in my logic or implementation.

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

Solutions to all problems in video format :)
solutions

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

Nice contest with interesting problems.

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

Hello, I solved 1 problem in Div 3's contest yesterday. But my rating went down. What is the reason?

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

Failed system testing for Problem E2, could someone tell me why this is TLE? The second last test case also had 200000 length but it passed well within the time limit. My code

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

    It is the unordered_map in the worst case time it's time complexity for insertion can be O(n) and not O(1). https://mirror.codeforces.com/contest/1579/submission/130266275 just by using map your code gets AC

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

      thanks, that's tragic. makes me wonder when the unordered_map shouldn't be used since i even passed the pretests so didn't give it a second thought

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

        Sometimes you might want to use pbds hash maps, like cc_hash_table and gp_hash_table. There are helpful tutorials on CF — the authors even mention how to prevent excessive hash collisions, which might be helpful for the casual unordered_map as well.

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

          I followed this blog and was able to pass the test cases. should I just keep it in my template? haven't seen anyone using this though

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

            I've seen ppl using this; personally I've used it a few times. But in this very case, it wasn't needed — note that ordered_set is very slow, but it is enough to complete this task. The operations we need to support are "add x to the set" and "count how many elements that are < / <= are on the set". If we somehow distinguish equal values appearing on distinct positions, we can complete this task simply with order_of_key queries. My suggestion is, instead of adding x to the ordered_set, add f(x) = (x * BASE) + pos, where BASE is some constant (sufficing BASE > n) and pos is the position of the added value. Now, for all values y < x, f(y) < x * BASE, and for all values w > x, f(w) > x * (BASE + 1) — 1. As you can see, the queries are pretty straightforward now, and we don't suffer from unordered_map etc.

            To conclude, sometimes changing the values might be easier and more efficient than the hash function.

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

Can someone please tell me the approach for F and G.

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

    F: If a position has a value of 0, it will never change. If a[i] = 1 and a[i + k] = 0 (where k is the length of rotation), then we can make a[i] = 0 in one turn. (maybe you need to switch a[i] and a[i + k], I don't remember if the rotations are left or right oriented)

    Let's build a circular graph of n vertices. If a[i] = 0, then dist[i] = 0, else set the initial distance of vertex i to inf. Then use a multisource BFS from all vertices with dist = 0 to compute the answer — the edges start at vertex i and go to vertex number i — k (mod n). Whenever a vertex labeled with 1 is accessible from a vertex 0, we add him to the queue, update the "distance" etc. The answer is the maximum distance over all vertices (or -1, if for any vertex v, dist[v] = inf holds after the computation finishes).

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

when will the editorials be released? (sorry for being a little impatient)