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

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

Все задачи были придуманы MikeMirzayanov разработаны мной Supermagzzz и Stepavly.

1472A - Открытки для друзей

Разбор
Решение

1472B - Честное разделение

Разбор
Решение

1472C - Длинные прыжки

Разбор
Решение

1472D - Четно-нечётная игра

Разбор
Решение

1472E - Правильная расстановка

Разбор
Решение

1472F - Новогодняя головоломка

Разбор
Решение

1472G - Переезд в столицу

Разбор
Решение
Разбор задач Codeforces Round 693 (Div. 3)
  • Проголосовать: нравится
  • +147
  • Проголосовать: не нравится

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

огромная благодарность за версию на русском языке!

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

How the editorial posted 2 years ago? If the contest is running.

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

Can someone please explain why in 1472G - Moving to the Capital you can't go in first sample:

6->2->5->1
corresponding d[i] is
[2]->[1]->[2]->[1]

so there is exactly one step of kind 2.

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

how can editorial be posted if hacking phase is still ongoing

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

anyone please explain d

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

    For D you only have to justify to yourself why taking the biggest number is always the best choice to make on your turn. The editorial actually does a pretty job of this, but think of it like this — either you take the biggest item left, and it matches your parity (i.e. add it to your score), or it doesn't (your opponent doesn't gain from that item on their turn — also good for you). It's simple to see that therefore a player should ALWAYS take the biggest item (i.e. sort the array and check each move).

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

    Another way to look at it:

    At each point the player wants to maximise the distance between the scores of one another.

    You may be tempted to look for parity while picking the numbers, but if the goal is to simply maximise the distance then you increasing your score is equal to hindering the others progress.

    therefore at each point you pick The largest number which has a potential to reduce the difference between two scores.

    I hope this makes sense.

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

Can someone please explain the approach for B (non DP approach)?

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

    Approach for problem B.
    Let the number of 1's is one & the number of 2's is two .
    Let total sum = one + 2 x two.

    Casework:

    Case 1

    Case 2

    Case 3

    Case 4.1

    Case 4.2

    You can also see my solution here : 103195164

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

      Used the same case by case exhaustive enumeration, but instead I just focused on remainders after division by 2 (one_cnt % 2 == 0, two_cnt % 2 == 1).

      count(1) % 2 count(2) % 2
      Case 1 0 0 The number of ones and twos is even. Possible to distribute
      Case 2 0 1 Needs more attention, because we could match extra 2 with {1, 1}
      Case 3 1 1 Not possible, because of extra 1
      Case 4 1 1 Not possible, because of extra 1
  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Lets say s represents the sum of all elements, If s is odd then its totally impossible to split it into two equal halves

    Otherwise if s / 2 odd then you need to have atleast one 1 in the array to make the odd half

    so the answer is no if (you have a odd total) or (a even total but odd half and no ones with you), else answer is yes

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

Problem B is really similar to Div-2A Kitahara Haruki's Gift (https://mirror.codeforces.com/problemset/problem/433/A)

Great Contest Overall

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

Can someone explain last testcase of Problem G.

For node 3 , shouldn't the ans be 1

we can go

3 (2) --> 4 (3) ---> 2 (1)

value in brackets is the corresponding d values

3--> 4 is of type 1

and

4--> 2 is of type 2

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

A way to avoid repeating the algorithm in E, is to always have H < W for every i. So just swap H and W for some person, if H > W.

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

Simple solution — let's iterate through how many candies of weight 2 we will give to Alice, then the remaining weight should be filled by candies of weight 1. If there are enough of them, then we have found a way of division. How is this true ? If we take the case of 1 1 2 2 2, then Alice will get 2 2, while Bob will get 2 ,1 and 1.

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

Here are my attempts to explain solutions in video form after messing almost everything up (this seems to happen more and more often recently...)

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

on G,can someone explain why (dist[u] must <dist[v]),my code doesn't add this condition and i got WA. Thanks!

if (!used[v] && dist[u] < dist[v]) { dfs(v, g, dist, dp, used); } (In the DFS function)

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

    Because you can use only the first option from the statement as much times, as you want. We build the new graph, with edges that satisfy this condition. The second option we check by DP.

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

      Hi, This is my Dfs function. Where did I perform the second operation twice?
      mark : stores the final answer.
      d : stores the distance from root.

       void Dfs (int t){
      vis[t] = true;
      for(auto u: g[t]){
      if(!vis[u]) Dfs(u);
      if(mark[u] < d[u]){
      if(d[u] > d[t]) mark[t] = min(mark[t], mark[u]);
      else mark[t] = min(mark[t], d[u]);
      }
      else mark[t] = min(mark[t], d[u]);
      }
      }

      Adding that conditon you mentioned, gives me an AC. Can you please tell, where am I going wrong? Thanks

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

      I am stuck in the same situation. Even without dist[u] < dist[v] condition, we seem to be ensuring that 2nd condition is only counted once because

      if (dist[u] < dist[v]) { // Only count dp[v] if it's not bridge
         dp[u] = min(dp[u], dp[v]);
      } else {
         dp[u] = min(dp[u], dist[v]);
      }
      
    • »
      »
      »
      5 лет назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится 0 Проголосовать: не нравится

      Thumbs up to the guys above. I also got stuck over this condition. For anyone interested, here's a graph exposing this bug:

      5 7
      1 2
      1 5
      2 3
      3 4
      4 5
      4 1
      5 3
      

      In short, without the dist[u] < dist[v] condition, your DFS may update answer for some vertex x (dp[x]) by using dp[y] at a moment when y is still being processed by DFS somewhere up the tree. In this case, dp[y] isn't finalized, it's just not ready. In the graph above, x is 5 and y is 3.

      Takeaway: DFS doesn't like when you close loops; better let the old DFS finish and only then spawn the new DFS tree to process x.

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

The editorial for G is very smooth. Great work Supermagzzz and Stepavly.

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

I don't know how people solve problem like today's D so fast !! sed lyf :((

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

I wonder with B they did not include the alternate solution with DP

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

Could anyone please help me to resolve MLE in this solution for Problem C

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

Why this dp solution gives WA on B.I thought it is equal sum partition. https://mirror.codeforces.com/contest/1472/submission/103310451

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

I came across an ID in this round which was submitting solution with wrong answer for a particular corner case. FOR eg if n==123234 then print "NO" , this was done so that it could be hacked by another IDs. :p

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

Can someone please help me why my code gets a WA(I get why it might get TLE but no WA): 103300499

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

Can someone please help me why my code gets a WA(I get why it might get TLE but no WA): 103300499

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

    wrong answer jury found the answer, but participant didn't (test case 11)

    This is a comment of your code, so you can look for test case 11(it is visible) and see why it doesn't work. EDIT: you're only looking for elements with smaller X but a correct answer could also be element whose X is larger Y is smaller and so when it is laid sideways than it could fit in the element that you are checking. So your for loop J should go from 0 to n (i.e. check all elements) P.S. even if you did this you would get TLE

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

Can anyone please explain why my solution is showing WA. My logic is obvious. One can easily get that after seeing my code. Submission

Thanks in advance for helping :)

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

    I think its because you didn't sort the arrays. You should always take largest number, and even if you divide numbers in odd and even you should sort the array and look for larges numbers. I used a similar approach 103227720. Hope this helps.

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

Can anyone explain problem G? Why do we have to change the graph? Why can't we apply dp on the graph with cycles?

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

I enjoyed the last dp problems of this contest :)

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

Does anyone else feel that E was too much implementation heavy?

I thought about exactly this solution but with 30 mins remaining.
Then dropped the idea thinking that it might have some better segment tree solution instead of so much implementation. lol

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

G was cool, E took me a while but it was fun too. Overall good problems!

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

Are we allowed (yet) to ask inquiries regarding hacks for this round?

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

Can anyone tell me how ans of this test case of ques d is TIE.

3 2 1

I guess here bob should win. First alice chooses 2, then bob goes with 3 . Then at end alice chooses 1 and removes it. So bob wins here(since score of bob is 3 and alice score is 2).

How is it draw?

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

    IF Alica pick 3 first, then if Bob pick 1 Alica wiil win because in next turn she will pick 2(Bob_score = 1, Alica_score = 2), if Bob picked 2 insted of 1, Alica will be left with 1 (Bob_score = 0, because he piced even number, Alica_score = 0, because she picked odd number). Then answer is TIE.

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

Can C be done by top-down approach?

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

Why is this Solution got hacked? It is almost same as the Editorial. Please let me know as I don't wanna to repeat the same mistake again. Thanks in advance !

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

I have two implementations for E which I think are easier than the one in the editorial.

A : With comments, Without comments

B : With comments, Without comments

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

DP Contest :)

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

For D first test case my code is giving right output in my pc whereas on codeforces it gives wrong output 103274282

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

I was given similar problem as D in one of my interviews and I couldn't think of greedy approach, could only come with DP approach and was rejected. Now I solved it with so much ease in comfortable environment. Hate interview pressure.

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

Can someone please explain E?

  • »
    »
    5 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +1 Проголосовать: не нравится
    1. Ask everyone to stand (make $$$h_i \leq w_i$$$ for every $$$i$$$).
    2. Sort them based on $$$h_i$$$ then $$$w_i$$$.
    3. Now we know that the $$$i$$$-th person is at least as tall as all of the people who come before him ($$$h_i \geq h_j$$$ for every $$$j \lt i$$$).
    4. Iterate through everyone and find the largest $$$j$$$ such that $$$j$$$-th person is strictly shorter than the $$$i$$$-th person ($$$h_i \gt h_j$$$). As they are already sorted, now we know that the $$$i$$$-th person is also taller than all of the people who stand in front of $$$j$$$-th person.
    5. Now we have $$$j$$$ possible candidates that can be placed in front of $$$i$$$-th person. We no longer have to check whether they are shorter than $$$i$$$-th person or not, because we already know that from the previous step.
    6. We need to find among the $$$j$$$ possible candidates, is there a person who is thinner than the $$$i$$$-th person. There could be more than one person who fits the criteria, so we will just greedily pick the thinnest person among those $$$j$$$ people and check if the thinnest person is thinner than $$$i$$$-th person.
»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In problem D (language used : JAVA 11) , I am getting TLE in testcase 10 with this snippet of code

while(t-->0){ int n = ni();

       int arr[] = new int[n];
       for(int i=0; i<n; i++){
         arr[i] = ni();
       }

       Arrays.sort(arr);
       int k=0;
       long a=0, b=0;
       for(int i=n-1; i>=0; i--){
         k++;
         if(k%2 !=0 ){
          if(arr[i]%2==0)
              a+=arr[i];
         }
         else{
          if(arr[i]%2!=0)
              b+=arr[i];
         }
       }
       if(a==b)
         pn("Tie");
       else if(a>b)
         pn("Alice");
       else
         pn("Bob");

    }

and getting AC with this snippet of code

while(t-->0){ int n = ni();

       Integer arr[] = new Integer[n];
       for(int i=0; i<n; i++){
         arr[i] = ni();
       }

       Arrays.sort(arr, Collections.reverseOrder());
       long a=0, b=0;
       for(int i=0; i<n; i++){
         if(i%2 ==0 ){
          if(arr[i]%2==0)
              a+=arr[i];
         }
         else{
          if(arr[i]%2!=0)
              b+=arr[i];
         }
       }
       if(a==b)
         pn("Tie");
       else if(a>b)
         pn("Alice");
       else
         pn("Bob");

    }

Can anyone help me to know what is the cause?

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

https://mirror.codeforces.com/contest/1472/submission/103236341 this is my solution of D main idea is what person must bring max(his parity, opposite parity(it means not give this element to enemy))

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

Can problem E be solved with monotone stack? Think the array to be circular, then for each element find the next element so that (h1 < h2 and w1 < w2) or (w1 < h2 and h1 < w2)

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

anyone can provide better sol for Problem E or any video

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

Hi, I am facing some problems with D. Even-Odd Game. I have read the editorial as well as the solution provided. I think I am doing the exact same thing given in the solution: always selecting the biggest available number for either player and adding or subtracting it from a global sum depending on who the player is and the parity. However, I am getting wrong answer on test case 3. ~~~~~

include <bits/stdc++.h>

using namespace std;

int main() { int t, n; cin >> t;

for(int i = 0; i < t; ++i)
{
    cin >> n;

    int a[n];

    for(int j = 0; j < n; ++j)
    {
       cin >> a[j];
    }

    int size = sizeof(a) / sizeof(a[0]);

    //sort array in ascending order
    sort(a, a + size);

    int score = 0;

    int num;

    int turn = 0;

    for(int j = n-1; j >= 0; --j)
    {
       num = a[j];

       //Alice Turn
       if(turn % 2 == 0)
       {

         if(num % 2 == 0)
          score += num;
       }
       //Bob Turn
       else
       {
         if(num % 2 == 1)
          score -= num;
       }

       ++turn;
    }


    if(score > 0)
       cout << "Alice\n";
    else  if(score < 0)
       cout << "Bob\n";
    else
       cout << "Tie\n";

}

return 0;

} ~~~~~

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

Thanks for this round. I like problem G very much, it is the classic Codeforces' style task. Quality of this round was much better than previous five or even more.

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

Для задачи G есть более простое решение: давайте запустим BFS из столицы и найдём все вершины v, для которых существует ребро в вершину u с меньшим расстоянием от столицы. Для каждой такой вершины вставим в вектор пару {d[u], v}. Отсортируем его по возрастанию и последовательно запустим DFS по обратным рёбрам a->b таким, что d[a] = d[b] + 1 из каждой найденной вершины, не обнуляя список посещённых вершин. Решение легко доказывается с помощью дерева обхода BFS.

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

In problem D i have used erase for deleting the element and it has failed, but i see solution with same logic but using pop_back() instead of erase getting their solution accepted. I want to know that whether the time complexity of erase more than pop_back() or are they same in c++ ?

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

I have a different solution for F, where I keep a offset between the top and bottom pointer, and use some case analysis. Time is O(mlogm).

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

As the problem D has a trival solution, I have faced a false plagarism accusion on it.

"Your solution 103217882 for the problem 1472D significantly coincides with solutions lit2019039/103212550, whohet/103217882."

This question has a really trival solution and hence is clearly a coincidence. Please help and remove this plagarism mark. This is literally a coincidence, as the problem really have same solution. My solution link https://mirror.codeforces.com/contest/1472/submission/103217882

Match solution link https://mirror.codeforces.com/contest/1472/submission/103212550

Please have a look as problem really have a trival solution

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

How does the code which was giving RE on testcase 4 with a slight modification in the comparator function (used for sorting) gives AC(aka happy new year). The change simply is using "<" instead of "<=". any input in this regard is highly appreciated

code with AC VERDICT:https://mirror.codeforces.com/contest/1472/submission/103375747

code with RE on test4 :https://mirror.codeforces.com/contest/1472/submission/103375782.

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

    I bealive comparator function should be unique. Meaning if A > B then B < A. In your case with <= you are saying that at that if A == B then a could be before or after B which should not be possible because then sorting is not unique. I.E. if your functions returns A < B it should also return !(B < A)

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

      I believe when you say "A<=B" that would mean that if A and B are equal then A should be before B , Although I understand what you are trying to infer, and I think that it could be right but that would depend on the sorting algorithm, furthermore if it was the case that A and B are repetitively compared with each other, shouldn't it result in a TLE instead of RE?

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

        I bealive it works that if you compare A and B, than comparator automaticly compares B with A, and it should yield same results. In your case it gives A before B in first, and B before A in second which is contradictory. And so it gives an error.

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

I felt E was harder than F. I spent wayy too long on E. Shouls have attempted F first.

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

Why is there a "Tie" in the second test at problem D?

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

Can someone please help me out for question D. My submission is showing runtime error on testcase 1 but it works fine on my ide

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

Is there any way that I can uphack my solution to G. It's linked here 103279910. I have tested it on custom invocation on CF and I know there is definitely a case that makes it TLE. I waited out the hack phase since I wanted to keep my rating, but now I don't see the option to hack it anymore.

EDIT: I think you have to be 1900+ to uphack. Here is my generator that would cause my solution to TLE. https://pastebin.com/uYxwMnYz

Any1 who is eligible to uphack, go for it :)

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

Link1 Link2

Problem E.

Link1 solution is accepted wherease link2 is not. The only diff between the 2 solutions is that for pair(hi,wi) whose hi is least is being calculated differently:-

In link1: let the main loop take care of everything

In link2: comparing all (hj,wj) with (hi,wi) for second condition [wj < hi && hj < wi = > ans[i] = j] [Since first condition can never be satisfied]

Why does link2 solution fail?

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

What's the DP state/solution for D no. problem? I can just feel the greedy approach. But problem tag shows DP too.

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

Another way to think about E:

We can think about the pairs $$$(h_i, w_i)$$$ and $$$(w_i, h_i)$$$ as points on a 2D plane.

Then the problem becomes: for each point $$$P(h_i, w_i)$$$, find if there is any point that lies completely inside the rectangle that is formed by the origin $$$O(0, 0)$$$ as its bottom left corner and $$$P$$$ as its upper right corner.

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

I've uploaded my post-contest stream to YouTube: https://youtu.be/nCSLlTCDnDs

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

For D how can this input be a tie? 3 2 1

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

Can someone help me find the complexity of this code:103390550? It just barely passed the 4s time limit.

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

wow that is so pretty!!!!

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

can someone please explain the DP approach from problem B?

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

I cant stand the fact that the dude on problem E invite n friends 1<= n <= 2 * 10^5 to celebrate new year! Guys we are in corona virus pandemic we should be more carefull! Imagine what will happen after 14 Days if there was someone with corona in the party! Be more carefule stay home and code, stay safe :D

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

Simpler solution for F: 103672111

  1. Sort the blocked cells by x, y
  2. Pair the adjacent(after sort) blocked cells in disjoint pairs.
  3. Between blocked ceils within the same pair: distance has to be odd(or opposite color in chess grid as described in editorial)
  4. Between the second cell from ith pair and first ceil from i+1th pair: they cannot be on the same column. Otherwise it's going to block the flow of white cells, which is going to create an odd number of white cells in both side, which is impossible to fill.
»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

i need help..! submission to D.

Please find what is wrong with this code Your text to link here.... i am not able to find any error.! it is giving runtime error.!

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

Does anyone know a possible reason for MLE in Problem G?

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

include <bits/stdc++.h>

using namespace std; typedef long long int lli; typedef long double lld;

define FOR(i,l,u) for(lli i=l;i<=u;i++)

int main() { lli t;cin>>t; FOR(k,1,t) { lli n;cin>>n; lli A[n+1]; FOR(j,1,n) { cin>>A[j]; } lli score[n+1]={0},maxi=0; FOR(j,1,n) { if(score[j]==0) { lli i=j; score[j]+=A[i]; i+=A[i]; while(i<=n) { score[i]=-1; score[j]+=A[i]; i+=A[i]; } if(score[j]>maxi) maxi=score[j]; } } cout<<maxi<<"\n";

}

}

why am I getting time limit exceeded? In the above code no element is traversed more than twice, so time complexity is-O(n) for each test case.

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

Kind of late to the party, but I think that problem G could be solved in a lot easier way. Firstly, just as in the official editorial, find out using BFS all the shortest distances from node 1 to every other node. Then we create 2*N states for the dfs (vis[2][N] = false and ans[2][N] = INF). First state will represent, if we already took the "larger to smaller distance edge" or not. Now, we will iterate through every node (v) and if vis[1][v] is false, then we do the dfs (our dfs will be defined as dfs(took, v)).

In the dfs, for each neighbor (u) of a current node (v), we check if d[u] > d[v]. If yes, we can go there. Else we have to check if took is 1. If yes, we can go into u, but we have to update took to 0. The dfs will be returning the shortest path found yet. Also, if we encounter a visited vertex, we just answer with the solution that we precalculated (recall ans array). For better understanding you can check my solution.