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

Автор KhaledFarhat, 16 месяцев назад, По-английски

We would like to invite you to participate in The 2023 Damascus University Collegiate Programming Contest that was held on 25th June in Damascus, Syria.

The problems were authored and prepared by Kaitokid, Obada_Saleh, Guess.Who, Eliaster, HeMoo, Borgov, EleCursity, Wael_Mchantaf, Salahiano, Tareq_Ali, Helal_Salloum, Edrisov, ETheHedgehog, and me.

Thanks to our testers: A.D., AboAbdoMC, LastDance_NotLastOfMe, Zaher, Naseem17, Mahmoud_Haddad, Space-Time-, Arturo, Magician_Mathematician1, roctes7, Mohammad.Nour, HazemDalati, BallzCrasher, Richtofen, KactusJack, Harraaak, Malek_, Hadi_Alhamed, 57rek, and A.L.S.A.

Special thanks to EleCursity who helped us coordinating the contest.

We would love to hear your feedback about the contest. Hope you enjoy solving the problems!

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

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

I am the author of problem G, and this comment is a motivation for you to read it to downvote me if you don't like it (or upvote if you like it?)

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

Thanks for the efforts of all the coordinators of this contest.

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

Any idea on how to solve H???

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

Painful day it was

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

How to solve I?

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

    Let's Reverse the permutation we note that the first $$$j$$$ such that all elements between $$$[1;j]$$$ exists in this prefix form a connected component this is easy to prove and you can find it out from doing some trials as well.

    So you just need to count the number of such $$$j$$$. This can be translated to the following problem: Count the number of prefixes such that $$$\sum_{i=1}^{j} i-p_i == 0$$$, Note that this sum will always be non-negative which translate it to this

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

Problems are very interesting kudos guys.

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

    Thnx.

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

    Can you post your solutions on pastebin for all problems please? I am curios about some of them.

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

      Too much work tbh :" Try to ask here thou :"

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

        Any hints for problem L?

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

          You need to think of the problems as at each step you add a maximum layer of nodes where no node is ancestor of the other, which means you need to add the first layer as answer to K=1 , the first 2 layers as answer for K=2 and so on. To build the layers you need to use small to big merge where you have for example layers from all childs and now you need to merge them for example layers of u are { 6,2,1} and layers of v are { 9,5} when you merge you will have {6+9 = 15, 2+5 = 7, 1} which means you merge the big from u with the big from v , after merging all childs, you add layer for the current node , here is my code if you want to take a look : link

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

nice problems. are editorials available?

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

any explanation on the first example of problem $$$M$$$ .

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

    for the first test case the possible permutations are: all permutations

    for the second test case the possible permutations are: all permutations

    for the third test case the possible permutations are: [1,3,2],[2,3,1], [1,2,3]

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

      Can you give me some hints for problem M?

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

        You can reformulate to think about the given indices in the set doesn't really matter if p[i]>p[i+1] or p[i]<p[i+1] , becaus if p[i]>p[i+1] then it is in the set otherwise it doesn't matter, so our problem is how many permutations such that if i isn't in the set than p[i]<p[i+1], I hope this helps!

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

How to solve B?

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

    You build a union find data structure with time , where you save the update time for every node and the corrosponding id and answer for that time. you have for example for node 2 has been updated at times 3, 6 , 7 you will have the following update_time[2]={0,3,6,7}, id[2]={2,2,2,5}, now to get the id for u and time t , you search for the biggest update time for u <= t and see , if it's equal to u then it's the id of the component otherwise recursively search on it's id like a simple DSU. , for the merge operation you keep set for every component , and save current ans for every component, you merge the small one into the big one, lets consider big is the big set and small is the small set, now we iterate over the items of the small set , let's say u is the current value we want to insert, if u is already in big continue, if u+1 and u-1 are in big the we decrease the ans by 1 (we merged them together) , if u+1 and u-1 not in big we increase the answer by 1 (a new component) and then we insert u into big and we continue iterating. Here is my code : link

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

How to solve problem A?

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

    First you need to notice that every value should exist at most 2 times . If a value exist only 1 time it doesn't matter where it should be A or B, If a value exists 2 times then you there are 3 cases : if the 2 poisitions of that values are the same it means there is i such that a[i]=b[i]=value then it doesn't matter we swap those or not so we skip. if we have now 2 positions i,j such that ai=V, bi=x and aj=V,bj=y then we need one of them to be swapped and the other no , se we will construct a graph with nodes are indices and edge weight =1 between i and j in this case.

    if we have now 2 positions i,j such that ai=V, bi=x and aj=y ,bj=V then we need if one is swapped then the other one should be swapped too. then we add to the graph an edges between i and j with weight 0.

    So we will build a graph with edges with weights 1 or 0 and see if we can color the graph with 2 colors such that edge with weight 0 means both end should have same solor and edge with weight 1 means both ends should have different colors. => bipartite graph

    And for the answer just get the minimum size of color_0, color_1 for each connected compoenent and sum them .

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

Hi, overall, nice problemset but problem A is basically this: G. Columns Swaps.
The only difference is that in Problem A the values are up to 2*n instead of n.
The code of problem "G. Columns Swaps" in the editorial can be slightly modified to get A accepted.