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

Автор Akulyat, 4 года назад, перевод, По-русски

1735A - Рабочая неделя

Hint1
Answer to Hint1
Solution

1735B - Чай с мандаринами

Hint1
Hint2
Solution

1735C - Сдвиг по фазе

Hint1
Answer to Hint1
Hint2
Hint3
Answer to Hint3
Solution

1735D - Мета-cет

Hint1
Answer to Hint1
Solution

1735E - Планирование дома

Hint1
Answer to Hint1
Hint2
Hint3
Solution

1735F - Камушки и бусинки

Hint1
Hint2
Hint3
Solution
Разбор задач Codeforces Round 824 (Div. 2)
  • Проголосовать: нравится
  • +74
  • Проголосовать: не нравится

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

lol I hopcroft-karp'ed the E

Upd: mine got tle lol. guess it's not my lucky day

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

well-balanced contest. thank you so much. hated it

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

logic in A was quite good!

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

I didn't even understand A... Just needed to find some $$$x$$$ from $$$0$$$ to $$$7$$$ such that $$$\lfloor \frac{1033-x}{3} \rfloor=342$$$

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

In editorial of D, what is a "central card"?

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

    It's the card that is shared by both sets in a metaset.

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

    It's a card that appears in two different sets within a meta-set.

    Two different sets can have at most one overlapping card (two overlaps would imply that the third must be the same as well, but then they're no longer different sets), so a meta-set (which has only five cards) can only fit in two sets if they have exactly one overlapping card. This card is considered as the central card of the meta-set.

    (I actually mentally used the term "central card" as well when thinking about this problem during the contest, even though the statement never suggested such a term; I guess the visual explanation kinda screams "central card")

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

    Thanks. I get it now. 2 sets means 2x3 = 6 cards, but we are only considering 5 cards. So 1 card is shared, or in other words, central.

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

Balanced Difficulties, great Problems, fast Editorial, all in one contest. Rated it as the best contest I have ever participated.

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

0≤hi,p1,p2≤2⋅109 for what?(((

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

My approach to D involved the key observation that three cards form a set if and only if the sum of values for each feature is 0 mod 3 (i.e., either i + i + i or 0 + 1 + 2). We can find the sum of every possible pair of cards, and count them in a structure (like a map). Then we iterate through each card in our input (to consider it as a potential central card) and subtract this card's value from 0 modulo 3 to get the required pair sum it can form a set with. We can then add sC2 as described in the editorial, where $$$s$$$ is the number of times this pair sum appears.

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

If we form a circle of size less then 26. Maintain any structure to check it.

Is there anyone who thinks he has implemented a very nice structure to check whether there is a cycle of small length or not?

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

    a very nice structure to check whether there is a cycle

    well we already have the DSU???????

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

      Writing DSU takes too much time i didn't had pre written code for it.

      And copy pasting code from online sites is not my style.

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

        Oh come on, I took less than two minutes typing it. You didn't even have to apply two compressions here, one compression (path compression is what I used) was more than enough.

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

        having some snippets is really useful. It makes your life easy a lot of times.

        I used a dsu, but it isn't necessary. You can store for each letter the previous and the next. When you make 25 connections in this structure you have a unique set and can connect the ends

        edit: no w8 that's not right. You still have to assign some number to the whole structure each time so you can understand if you aren't connecting a loop too soon. But you can do it the stupid way assigning an id to each member of the sequence you change each time. It's like O(n+alphabet²) complexity if i'm not wrong

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

          You don't need a number for the whole structure; just storing the previous and next is enough, due to the nature of this problem. When we want to consider whether we can assign $$$c_2$$$ to be after $$$c_1$$$, this requires that $$$c_1$$$ doesn't already have a next character assigned, and $$$c_2$$$ doesn't already have a previous character assigned. So you can simply check the previous character from $$$c_1$$$, and then the previous character of that, and so on, counting how many steps this takes. If we took 25 steps, then the chain has all 26 letters, and we only need to complete the cycle. Otherwise, we can only link $$$c_1$$$ to $$$c_2$$$ if $$$c_2$$$ isn't at the end of this predecessor chain from $$$c_1$$$.

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

      A simple while loop will work. 174406487

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

    I used DSU, which is probably overkill when the size is max 26.

    It should suffice to simply store which character precedes another in our circular wheel, using a simple array, e.g., pred[0] = 3 means D precedes A. To check if it's okay to set $$$c_1$$$ as the predecessor of $$$c_2$$$, we can check the predecessor of $$$c_1$$$ and then its predecessor, and then its predecessor, and so on. If we find $$$c_2$$$ at some point, then it forms a cycle, which is only okay if we saw all 26 letters in this chain. You could, of course, store successors instead of predecessors with similar logic.

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

In E distance arrays can be sorted just once and then each candidate (distance between $$$p1$$$ and $$$p2$$$) can be checked in $$$\mathcal{O}(n)$$$ with two pointers resulting in $$$\mathcal{O}(n^2)$$$ complexity

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

I think Problem A was very confusing.

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

Can someone please explain why was l1 = 1?

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

Can someone tell me what's wrong is my approach for A or I read it incorrect? For a 0 based indexing,

I marked index 1 as Off Day, so I have index n-1,1 as Off days and now I need to find one more index which is Off such that my answer is maximum. I did that by finding such possible index b/w 1 and n-1. I can't take index 2 and index n-2 as Off days as they are adjacent to index 1 and index n-1. So I have (n-2-2)-1 possible indexes for the 3rd Off day. I choose this position by finding the middle of middle of that subarray. So the 3rd Off Day should be res/4 + 3 by my logic where res = (n-2-2)-1.

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

    I think you're making it complicated by thinking on indexes. If you think about the way the intervals become it should get more clear. You have this setup: |w-ww...ww-| with a gap of length 1 and a gap of length n-3. Now if the answer is x the ranges are 1, x+1 and 2x+1 long (add the remainder to the last). The ranges x+1 and 2x+1 are in the part that's long n-3, so you can find x by the simple equation n-3 = 3x+2 + 1(this 1 is the day off) => (n-6)/3 = x

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

got FST on pE, at first glance I think it is because dinic but turn out to be map<int, vector<pair<int, int>> being tooooooooo slow :/

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

fix the latex typo in B solution it looks like:

[2 \cdot a_1, 3 \cdot a_1 — 2]

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

damn these aholes destroy the fun** https://www.youtube.com/watch?v=IZSyj2pTe_I T_T

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

In problem D if it is allowed that 2 cards have the same feature set then problem becomes really hard I guess. If anybody has any solution ideas to this

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

did anybody else find B confusing ?

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

SORRY to Bother u by mentioning :"" Akulyat... But i think some links in problems' codes are swapped.

BTW.. A,B,C Problems are great ^_^

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

I assume it was unintended, but a lot of $$$O(K N^3)$$$ solutions passed under the time limit in D.

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

In B why would you not just half the values at each step rather than removing 2 × a1 — 1 at each step?
Surely if you repeatedly half the value it will get smaller soon which means less number of steps.

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

    Halving each time is not correct. For example, take 2550 -> (halving) -> 2 pieces of size 1275 for those 2 pieces, we again need to use 1-1 operations to make all pieces less than 1200 (600*2), so in total, we used 3 operations while we only need to use two operations if use operations like this 2550 -> 1199 and 1351, 1351 -> 1199 and 152

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

The link to the code for C problem , directs to the solution code for D problem. An update would be appreciated :)

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

FIX

You accidentally put the link of D submission in the Code section for problem C.

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

The solutions are not at the correct question number.

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

Provided solution for problem D looks wrong: https://mirror.codeforces.com/contest/1735/submission/174443540

Sample testcase: 3 3 0 0 0 0 0 0 0 0 0

Actual answer should be 0. But it gives 9. This is happening because it doesn't take into account that central card should not be part of calculated set of pairs from which meta-set is created.

Akulyat: can you please look into this?

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

could someone explain editorial of A problem ... I am fine till "If we increase both values under the minimum scope by one, solutions don't change: maximize min(l2,(n−3)−2⋅l2)" but after that things are above my mind .

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

has someone solved problem A with binary search ?

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

can anyone explain ques C. Its difficult for me to understand whats written in editorial.

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

I got wa on pretest 14 in problem F during the competition, but when I replaced double with long double I got accepted... My error was about 10-5...

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

    Yeah it's a little unfair for languages that don't have 80-bit floating point (and those who may avoid long double out of principle due to architecture specificity). I basically had to hand-roll fixed-point arithmetic just to get it to pass in Rust: 174869219

    Interestingly it is important in this implementation that the multiply be performed before division, otherwise it loses enough precision to fail.

    UPD: I found a way to get 64-bit floats to pass: 174932779, compare with failing submission 174826031. Basically, truncating the convex hull from the "pebbles" axis first apparently gives more accurate results, since that's the result you have to output.

    It may also be more optimal for accuracy if, when interpolating, you reuse the slope values from the input, rather than recalculating the slope from the rounded-off endpoints.

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

I don't know why but I felt A to be bit harder than usual.

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

Does anyone have ideas on how to solve D if the cards are NOT distinct?

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

    There is two option :

    1-ABCDE = combine ABC and CDE and ignore clones of them. Use clones just for how many different A can come etc.

    2-AAA??, AAAA??, AAAAA = iterate A over all different cards and let $$$x$$$ be frequency of a card increase ans by $$$C(x,3)*C(n-x,2)+C(x,4)*C(n-x,1)+C(x,5)$$$.

    There's an intersection AAABC and you can calculate it with iteration over suitable ABC's (iterate A and B, find C at $$$O(log(n))$$$) and some combinations using A, B and C's frequencies.

    But this solution can require so much casework.

    (Sorry if this solution is wrong or has missing part, and for my poor English.)

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

Deleted

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

Very good round, I like all the problems!

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

https://mirror.codeforces.com/contest/1735/submission/174486190

can anybody tell why my solution from problem D gives me wrong answer ?. I am taking ith card as central card and finding no of sets formed with ith card as central card.

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

    Consider this case:

    case

    It is the same as the first example, only that the card "0 0 0 0" is now the last card. Your code returns 0, but the correct answer is 1.

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

This round is so great that I cannot understand the meaning of the problem D.

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

Can someone explain the flows solution to E?
I get the general idea, there are $$$O(n)$$$ possible values for the distance between $$$p_1$$$ and $$$p_2$$$ and you run a max flow for each of these options, what I don't quite understand is how, for some house $$$h_i$$$ and some candidate distance $$$d$$$, it could be that $$$|p_1 - h_i| + |p_2 - h_i| = d$$$, or $$$||p_1 - h_i| - |p_2 - h_i|| = d$$$, how do I formulate this into a max flow / max bipartite matching problem?

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

    Actually $$$|p - h_i|$$$ is just the distance between point $$$p$$$ and the house, so the above equation can be rephrased as $$$d_{1, j} + d_{2, k} = d$$$ or $$$|d_{1, j} - d_{2, k}| = d$$$ for some index $$$j, k$$$.

    So just let $$$d_{1, 1...n}$$$ be the vertices of left part($$$L_{1...n}$$$) and $$$d_{2, 1...n}$$$ be the vertices of right part($$$R_{1...n}$$$), and for every pair of $$$(j, k)$$$ satisfy $$$d_{1, j} + d_{2, k} = d$$$ or $$$|d_{1, j} - d_{2, k}| = d$$$ connect $$$L_j$$$ and $$$R_k$$$.

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

can anybody tell why my solution (https://mirror.codeforces.com/contest/1735/submission/174557086) from problem E has tle, but https://mirror.codeforces.com/contest/1735/submission/174558165 — normal what is the difference?

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

a harder version of D with k<=100 or with more than 3 values for a characteristic would be great imo

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

I really liked problem d

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

174937931 I understood the editorial of C but I am unable to find whats wrong in my solution. I am getting WA in test case 3. If possible can someone tell me the test case where my solution is wrong.

Thank you in advance.

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

C and D are really good problems, I especially love how D balances implementation and thinking so well.

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

My E was TLE on #45.

Anyone can tell me why it got TLE?

Submission: 175739035

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

[deleted]

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

Why does set or map of string takes far more time than set or map of vector doing same operations . See my submissions there is a reasonable time reduction . Submission — https://mirror.codeforces.com/contest/1735/submission/266351992 (890ms) https://mirror.codeforces.com/contest/1735/submission/266349652 (3889ms)

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

Akulyat In problem 1735B, let assume the following input:

1
2
2 10

Here the max size of a peel could be 3 (2 * 2 - 1), if we break 10 into smaller parts then it would be something like this, 3, 3, 3, 1. So the total units will now become 2, 3, 3, 3, 1. As per the above solution this is correct. But my point is that there exists 1 and 2 in the answer and 2 >= 2 * 1.

Wouldn't it be incorrect?

Any explanations are welcome.