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

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

We would be happy to invite you to participate in 2023 ICPC HIAST Collegiate Programming Contest that was held on 17th July in Damascus, Syria.

The problems are authored and prepared by Zaher ,SaeedSabbagh, OmarAlzakout, Yaman_Alwaza, Abdulrahman27, Khaled_Mardini, Ahmad7_7, Ismail_Alrifai, yaser.harba, and me.

Thanks to Kaitokid and HeMoo for testing the contest.

And Special thanks to EleCursity for helping us to coordinate the contest onsite and his efforts to ensure that everything ran well.

We would love to hear your feedback on the problems in the comments section. Hope you enjoy solving the problems!

UPD: it seems that there were something wrong with time limit of problem A, We've updated the time limit and all accepted solutions were rejudged, We do really apology for that wrong but too many non accepted solution have passed tests which made the problem too silly compared to the intended solution, We advise to try to solve the problem with the intended solution since it has a nice idea.

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

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

wlak 3aaash

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

Waiting for this!

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

The problems are so interesting that I wish I can forget the problems and participate as a contestant :(

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

Big up!!

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

As a problem-setter, I can assure you that the problems are interesting and I encourage you to try solving them all.

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

Great problems from great people <3

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

As a problem setter, I assure you that there are many good problems. I highly encourage participants to share their valuable feedback. Happy problem-solving to all participants!

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

Interesting problems with a lot of new ideas!
Waiting for the editorial :D

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

To be honest, amazing problemset. I solved some with too much excitement. Thanks for this :)

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

What a contest!!

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

As a participant, I truly enjoyed solving the problems. I can assure you that you will find the problem set very interesting. Thanks all for your efforts.

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

i'm using sparse table for answering queries in o(1) in problem B but still getting TLE on test 25 , any hints ? :((

update: AC folks , thanks for the great problemset

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

    I have the same problem how did you solve it ?

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

      i just added this line to my code and it passed

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

        Sadly it didn't work for me

        But it's a great line thanks :)

        my complexity is n*log(n)^2 is there something less?

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

          O(Nlog(N)) is enough , i took a look at your code and i think you should process the priority queue after taking the elements first (ignoring the ones for sure)

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

Thank you all for a great problemset.

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

Great contest!

Can anyone explain the solution of B as I get MLE/TLE when implementing NLog^2(N)?

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

    you can use priority_queue to get the max and divide it by its largest prime factor but it will still n.log^2(n). to get rid of priority_queue or set, i use a frequency array. first store for each number from 1 to 2e6 the largest prime factor using sieve in an array p. then lets store for each number from 1 to 2e6 the indices where it appears in the array using a vector. then iterate over this array of vectors from 2e6 to 1. if the current i is prime then sort the vector and set ans[v[j]]=t (where t is the time),otherwise move all elements of the vector to the vector i/p[i] (and increment the time while moving them). each element will be moved at most log(a[i]) times ,and the sort complexity overall is O(n.log(n)) since each element has exactly one final state in some prime index.so the total time complexity is O(n.log(n)). i hope this helps you :)

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

time for B too tight: https://ideone.com/6J3igi this passes in 2,9 sec (tle at 3) how can I improve it?

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

    Your solution is N*log(N)*log(max a[i]). There is an N*(log(N) + log(max a[i])) solution which pretty much fits the time limit. I mean it wouldve been too easy jf the solution was that straight forward right?

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

The best solution i could think about at problem I was O(2^min(n0/lo,n1,l1) by inclusion exclusion which clearly did not pass. Can anyone here provide a hint/solution? thanks.

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

    I hope this helps you.

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

      Your hints really helped me, thank you. Such a good problem for practicing combinatorics.

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

I can't find the solution. May I ask where the solution is?

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

problem K is interesting. Please anyone tell me how to solve K? thank you.

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

    Notice that the strings are sorted. Therefore, we can perform a binary search on them. Now, we have only 26 characters, so in each query, we can iterate over all characters. Let's denote the target character as 'C'. First, we perform a binary search on the strings 'a' and 'b' to find the first joint occurrence of 'C', which we will call "first". Next, we find the last joint occurrence of 'C' in 'a' and 'b', denoted as "last".

    To calculate the answer, we add (last — first + 1) for each character and continue this process for all characters. Finally, we print the answer for each query.

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

Could anyone kindly assist me in identifying the correct state for the DP solution in problem A? I attempted to solve it recursively using a map with a pair of int and a vector of size 10. The int for id, The vector is meant to keep track of the number of digits used.

My transition function involves two choices: either not taking the number or taking the number, adding its value, and updating its digits to my vector. However, if any digit becomes greater than or equal to 3, I avoid the recursive call since it leads to invalid recursion.

Unfortunately, this solution is inefficient and results in a Time Limit Exceeded (TLE) error on test case 11.

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

    The time limit is too tight. greedily sorting the array in descending order before DP worked for me.

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

      Still giving me TLE :/

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

        sadge :( i also included the id to the vector instead of using pair to reduce map time. i think better approach is to use 2 bit musk.

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

        BTW you sorted the array in ascending not descending

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

    You can simply solve it using an array with 11-D array !!

    First you have 1-D for id . Then you have 10 values — The Frequency of each digit of the numbers chosen so far.

    The Transition is the same as above — but I should mention that you have to check if frequency is still valid before choosing (Don't choose then avoid the recursive call). Because array size in this solution equals to 100*3^10 and can't be any larger (You can't store frequency if digit occurs 5 times or more).

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

      you can simply use the same idea of bitmasks but in base-3 it is much faster and easier to code

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

first , thx for the Interesting problem set

can any one help me in J

my idea is to assume that x is to the left,right or equal to MED then

1)find MED

2)calculate $$$x = (n+1)*MED — sum(before \space adding \space x)$$$

3) minimize ans

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

    Notice that after sorting the array, you are left with only two options: either make 'a[n / 2 — 1]' the median or make 'a[n / 2]' the median.

    In the first choice, you need to add 'X' before 'a[n / 2 — 1]' so that it remains smaller than 'a[n / 2 — 1]'. In the second choice, you need to add 'X' after'a[n / 2]' so that it remains bigger than 'a[n / 2]'. Now, let's calculate if this scenario is feasible. Let the sum target be '(n + 1) * a[n / 2 — 1]', denoting it as 't1'. You already have the current sum, which we'll call 's'. Therefore, it's evident that 'X' must be equal to 't1 — s'.

    If '(t1 — s) <= a[n / 2 — 1]', then the answer can be printed.

    However, if '(t1 — s)' turns out to be greater than 'a[n / 2 — 1]', it indicates that the first choice is not viable. In this case, since an answer always exists, the second choice is the correct one: making 'a[n / 2]' the median. Now, calculate the new target sum as '(n + 1) * a[n / 2]', denoting it as 't2'. Then, print 't2 — s' as the answer.

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

      thx. I think my solution fails when I assume it's the median.

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

There's a clarification that's been sent during the contest for problem M and the statement is not updated. Please note this ahmad_alghadban as the clarification was important to solve the problem.

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

Any hints to problem L? thank you.

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

    The edges not used in the m paths, add nothing to your discount so have their weight equal to zero. An edge included in some of the m paths will add a discount equal to the number of paths its included in times its weight, so replace its weight with this value instead. The K vertices will form a subtree, and no matter how this subtree is going to look like, you can cover it with at most K leaves of the original tree. let's say we choose two vertices among the K vertices we need, the best possible for them is to have the maximum path weight (diameter of the tree). Now for the K — 2 vertices left, you try figure it out :)

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

How to solve D? Can anyone give me the solution or some hints, please.

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

    First notice that the order of the elements is not important as you will sort it anyway, so you can define the subsequence using the frequency of every digit in it.

    From that, you can use dp[i][j], the sum of all cost of strings consisting of the first i digits and the length of the string is j.

    To update that dp you will need another array ways[i][j], which will hold the number of different strings.

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

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

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

really wow lovely contest Thanks all for your efforts.

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

What a great problemset!! I REALLY ENJOYED IT !

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

Could anyone give hints about problem C ? Thanks in advance

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

    The expected Value $$$e = \frac{\sum p_i}{n!}$$$

    Hint 1 : How can we simplify this expression ?
    Hint 2 : How many times can this pair appear over all permutations p ?
    Hint 3 : What is the final value of e ?
»
14 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can somebody give the answer of A or K thanks!!!

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

    Hints for 104493K - Sam-Oh, the funny coach: As the given string are sorted so, we can just store the starting and ending position of each 26(a to z) character for every string. Now for each query just go through the stored index of each 26 character add the length of intersection of both string and finally print it (note: Try to store index in light structure otherwise there will be MLE or TLE)!

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

Could anyone provide some hints on problem N? I thought about storing dfs order in treap so queries of type (2) and (3) would be easy. But how do I know where to insert another node? I think I should either maintain sizes of all the subtrees or "the most right" node in a subtree.

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

    You can build a treap that when you insert, put u and -u before the position of -father[u], for example in the test case the treap is something like "1 2 -2 3 4 -4 -3 -1", and if 3 has a new child, the array will be "1 2 -2 3 4 -4 5 -5 -3 -1". I don't now if this really works because I got MLE in the test 15, because I don't know treap so much, but I thing that's ok.

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

      I actually realized that you can avoid inserting new nodes. Since the queries are offline you can build the final tree first and do operations in reversed order (remove new nodes instead of inserting). My implementation uses two treaps and it got AC.

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

Can anyone give me some hints or solutions for problem L ?

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

    Remember that three points define an unique circle, and you can find easily some material to find this circle. Try to use a bit of combinatorial to solve the rest of problem.

    Hint: Remember that a O(N^3) solution get accepted in this problem.