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

Автор MateoCV, история, 2 года назад, По-английски

Hola Codeforces!

I am happy to invite you to Codeforces Round 774 (Div. 2), which will take place on Mar/04/2022 18:35 (Moscow time). Notice the unusual time! The round will be rated for participants with rating lower than 2100. You will have 2 hours to solve 6 problems. The problems were authored and prepared by me.

I would like to thank the following people who made the round possible:

See you in the standings!

UPD:

Scoring distribution: $$$750$$$ — $$$1000$$$ — $$$1250$$$ — $$$2000$$$ — $$$2500$$$ — $$$3000$$$

Thanks to ak2006, video editorials for some of the problems will be available on his channel after the round.

UPD: Editorial

UPD: Congratulations to the winners!

Official winners:

  1. lydia1
  2. mjhmjh1104
  3. Turret
  4. Vsinger_MoQingxian
  5. WAduck
  6. woolim
  7. Iam1789
  8. yagoo
  9. Koba.rde
  10. dtc03012

Unofficial winners:

  1. Vercingetorix
  2. Um_nik
  3. hank55663
  4. Umi
  5. dlalswp25
  6. disorientation
  7. rainboy
  • Проголосовать: нравится
  • +643
  • Проголосовать: не нравится

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

Good luck and high rating.

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

Good luck to all Ukrainian contestants

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

Note The Unusual Timings (1 Hour Late)

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

gl ^ hf

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

best of luck for all♥️

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

Good luck and positive rating!!!

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

This will probably be my first contest in over a month...I'm awaiting -100 delta :P

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

Good luck everyone. Maybe this round will help improve people's mood at codeforces.

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

    hello gagan plz guide me as i am stuck in newbie-pupil phase from a long long time and i don't see improvement also provide tips for dp if any. thnx in advance.

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

      The key to improvement is indeed just good-old practice. Now, everyone should choose a practice regime which suits them well. I just like you were shuffling pupil and newbie for 1 year. This year I started practicing more with a focus on solving questions rather than learning new algorithms. You only need a handful of algorithms like dfs-bfs, Dijkstra, dsu, segment tree to reach the expert but dp practice is very important. I practiced dp from problemset with filter-tag and started solving from 1000 rated questions and gradually increased rated questions. When I felt like I can do 1600 rated dp questions pretty confidently then I started randomly doing questions with gradually increasing difficulty from 1000 to 1600.
      Make sure you actually solve the questions and don't see the editorial until you solve it. If it seems impossible then try to read other people's code before checking out editorials. Do cp with your friends, discuss approaches and try to outrank your peers :p. This is what has worked for me till now, hope this helps you. Good luck!

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

        I think DP is the most important thing. segment tree is not too important at pupil stage.

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

          I was talking about the concepts which can land you to expert level.

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

            expert level doesn't need segment tree to be fair, binary search, greedy, simple DP, DFS/BFS and a little knowledge of graph.

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

Maybe we have the opportunity to just focus on this round itself!

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

Look at the quality of the questions. My hands are too slow.Orz

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

Before the usual time was 16:35, then 15:35, then 11:35 ... What is the actual usual time ?

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

ooo thanks

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

Are we going to fight against "Robot" in this round?

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

May C problem be solved by less than 2000 people. I want it to be an interesting one.

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

    Bruh This is every Cyan dream . That it has less than 2000 solves and we are among them . But sadly cheaters will never make it happen ;_;

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

      I would say and pupil too — last 3 contests happens to me top 1000 after A,B (top 100 last round), and then somehow stuck on C, and -∆, -∆, -∆

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

First argentinian contest! Congratulations MateoCV

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

Contest after long time.Eager to participate

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

Good luck everyone! Have a good contest!

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

Argentinian round? Aguante el Diego, Talleres y FaMaF!

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

Good luck!

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

Unfriendly time for Chinese contestants.

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

Dear contest, How do you feel today? Yet another person commented on your announcement page rn (me). Since I said hi to you, please give +ve this time to me. yk the usual. thanks in adv

Regards, that random user asking for +ve in rating

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

Very cool scoring distribution 1000 — 750 = 1250 — 1000 , 3000 — 2500 = 2500 — 2000

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

there is no as a tester comment.

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

SpeeeeedForcesssss

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

antonforces

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

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

I haven't coded recursive code in 2 years lol good to remember it with problem C

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

It took me 2WA's and 50 minutes to figure out that for long long integers __builtin_popcount doesn't work and we need to use __builtin_popcountll ... :-/

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

    I realized it just before click submit button...

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

    You should keep such things as #define (macro), easier to remember

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

    I suggest using std::popcount(). The only issue with this function in terms of competitive programming is that it requires x to be of unsigned type, so we have to cast explicitly if x is long long.

    int popcnt = popcount(uintmax_t(x));
    

    Of course, the simple macro solves this problem: #define popcnt(x) popcount(uintmax_t(x)).

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

5th test case of problem D...

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

it was so fun to write 15 nested for loop in problem C(p.s. I know recursive solution would also work)

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

Imagine wasting 20 mins debugging E because you "simplified" $$$\frac{lcm(x_1, x_2, \ldots, x_k)}{x_1}$$$ to $$$lcm(x_2, \ldots, x_k)$$$ without thinking properly T_T.

Also I can't exactly describe it, but CDE feel like they are somehow standard yet fairly interesting at the same time. Maybe its because they have extremely simple and natural formulations which don't feel like they've been forced to match an idea?

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

A nice contest for me!! I loved the problem C. Would love to share my experience while solving problem C,

Initially after reading the problem , I immediately thought of solving it using subset generation through bitmasks , because i thought the size of factors + powers of 2 would be around 30 , but turned out it was ~52. So i drifted a bit & thought of solving it using DP(using coin change approach) but that is also not feasible.

Solution :

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

    you only need to bitmask factors, then greedy choose powers of 2 for the rest.

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

      Yup, thats what i did. I don't think you need to greedy choose powers of 2 for the rest , because the remaining number's binary representation containing the set bits already is the least number of powers of 2 required to represent it.

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

Logic for C?

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

    Note that n can allways be constructed with number of its bits, since these are powers of 2.

    So construct all possible sums of factorials (that are at most 2^14 since there are only 14 factorials in range), subtract each one from n and count the bits of the difference.

    Smallest number of set bits in difference plus bits in factorial sum is ans.

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

How to do F?

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

What d hell is test case 5 of D -_-

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

    Either a large graph or something that kills the incorrect bipartite idea I guess.

    Try the following graph if you don't get why bipartite is incorrect:

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

    There are cases where it is optimal to not take two neighboring nodes. Splitting the tree to a bipartite graph and then taking one of the two parts is not always optimal. The idea is similar to the well-known DP problem "Maximum sum over array such that no two elements are adjacent" but implemented on a tree.

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

    2,3-dimethylbutane

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

My Idea for D :

  • Take all leaves to be good vertices
  • Now all parents of the leaves (call it buds) are assigned with weight = 1
  • Now the graph is split into separated sections with "buds" as boundaries for each section
  • For each section, I solve them independently by coloring it "bipartitely". In each section, I find which gave me the best arrangement whether the color "black" / "white" on this section are good vertexes and bad vertices for its counter-color.

I got WA on pretest 6. Not sure if the idea is wrong or my implementation My submission : 148381092 Any thoughts?

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

    I tried the same thing (but failed pretest 5) :(

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

    it is true that a good vertex(blue) must be surrounded by bad vertices(black) but it is not necessary that bad vertices be adjacent to good vertices. so if u two color the tree, u wouldn't take into consideration cases where two adjacent nodes are bad

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

    Pretty sure it's finding the max independent set.

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

      I did it in sort of dp style. Rooted the tree at 1.

      dp[i][0] = <C,S> means ith node is not good and fill its children however you want such that max good vertices below my subtree is C with sum of edges as S.

      dp[i][1] = <C,S> means ith node is good and fill its children however you want such that max good vertices below my subtree is C with sum of edges as S.

      For transitions dp[i][1] depends on dp[c][0] where c is children of i since you are good, children can't be good.

      dp[i][0] picks dp[c][0] or dp[c][1] according to which is best.

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

    How does the problem change after removing all the leaves?

    If there exists some tree for which bipartite doesn't work, I can just create a new tree by attaching a single node to each leaf and your soln won't work for it.

    And try the following graph if you don't get why bipartite is incorrect:

    Input Graph
    Answer
    A Correct Solution
    • »
      »
      »
      2 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      i defined dp[i][0] = max good vertices if vertex i is good and dp[i][1] for bad. and dp[i][0] = 1 + all dp[ne][1] in neighbours and dp[i][1] = max(dp[ne][0] and dp[ne][1]) for all neighbours. Is is correct ? i kept getting WA in either pretest 5 or 6

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

        I guess in dp[i][1] case if dp[ne][0] and dp[ne][1] are equal then how are you ensuring which one to pick to get minimum sum.

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

          Yup, this is likely the issue.

          One way to solve this is to store the dp value as a pair $$$<\text{max number of nodes}, -(\text{min sum of degree})>$$$, then taking max works as expected.

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

      Oh I see. I get it. Thanks!

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

      Wait, in your explanation should it be $$$dp_{x, 0} = max(dp_{v,0} , dp_{v,1})$$$ ?

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

Could someone share their approach for B ?

I tried solving it by sorting the array (minimize the Blue sum) and using prefix sum, but failed. I think this is because my approach colored all the numbers.

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

    Use sum of two smallest numbers as small sum, and biggest number as big sum.

    If both sums are ok ans=YES else add next smallest number to small sum, next biggest number to big sum. Repeat.

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

    Well, I also sorted it first, and then kept on calculating Blue Sum from the start and Red Sum from the end of the array. Also, to maintain the count(Blue) > count(Red), I initialised the starting index to be 1(0-based indexing) while initialising Blue Sum to be equal to the first array element.

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

submitted C in the last minute

took more than 1 hour to realize brute-forcing all subsets of factorial values is feasible

but brute-forcing all subsets of 2-power values is infeasible which gave me a wrong intuition that the factorial counterpart is also infeasible

I hope in the future I can be more familiar with the thresholds of feasibility.

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

    Why we Can't use one factorial two times?

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

    Even if it was feasible to brute force all powers of 2, how would you find the needed amount of factorials?

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

      I don't know how to find the needed factorials except for brute-force, so I should have taken that approach initially. Unfortunately the infeasibility of brute-forcing 2-powers gave me the wrong intuition that brute-forcing factorials is also infeasible.

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

      No Idea. That is why I was not able to solve C. Was expecting there is some other trick to solve the problem which I was not able to think.

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

      There are not much factorials in range, it is only 14 numbers. So you can create only 2^14 sums from these numbers. Just try all of them.

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

    Went through the same trajectory, except I took even more time to realise this and couldn't submit my code in time :( It also somehow escaped by mind that combinations of powers of 2 literally define every single number in exactly one possible way.

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

Thanks for the contest, I don't know why I did so dumb on A and B, But after all I really liked the problems.

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

In c, finding all the numbers powerful in a set then take a number which are just less than n and subtracting them from n is not feasible why?

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

what is pretest 6 of D? ಥ_ಥ

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

    If you were doing BFS solution from leaves, It would fail. Optimal solution will be reached by dynamic programming.

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

I think D is just Maximum Independent set with least total degree which can be solved by dp. I realised this, but could not reconstruct the solution from the dp before the contest ended.

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

How to solve E? I was looking for numbers with the same prime factors

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

    Take 2, 4, 8, ... as example. In the row starting with 2, you get 2^1, 2^2, ... In the row starting with 4, you get 2^2, 2^4, ..., so what in the cells are these powers of 2: 1 ~ M, 2 * 1 ~ 2 * M, 3 * 1 ~ 3 * M, ..., depending on how many powers of 2 are less than or equal to N. Then, what you need to do is calculate how many distinct number is in this list. Sum up all the length of lists of a number that is not power of another one. Don't forget 1.

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

Any counterexample on D solving with 2-coloring?

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

    6

    1 2

    1 3

    1 4

    4 5

    4 6

    The output should be:

    4 6

    1 1 1 1 1 1

    The idea is that although there can be no 2 adjacent good nodes, this does not mean that there can be no 2 adjacent bad nodes. Unfortunately I realized that a short time just before the contest ended.

  • »
    »
    2 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится
    Input Graph
    Answer
    Visualization
»
2 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Hey,
In the first problem, why this works cout << s/(n*n) << '\n';
but using cout << (int)(s/pow(n,2)) << '\n'; gives wrong answer in test 2?

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

    because pow() returns double which may cause precision issue.

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

    It turns out s/(n*n) is bounded within INT_MAX because bounds of s depend on n. Problem was caused due to precision issue of pow() as Aging1986 pointed out.

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

tried dp in D but it doesn't work... so retried bipartite and failed again.

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

Is it possible to output -1 in c ??

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

Getting MLE on test 39 on problem D just because I used longs and a relatively high memory constant is the most unfair thing ever...

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

Auto comment: topic has been updated by MateoCV (previous revision, new revision, compare).

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

Auto comment: topic has been updated by MateoCV (previous revision, new revision, compare).

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

Nice contest!

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

Ratings updated preliminarily. We will remove cheaters and update the ratings again soon!

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

Would this idea work for D?

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

    It won't work

    Edit:

    Actually I don't know.

    Edit2:

    I've coded it — it doesnt find the minimal value correctly.