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

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

How to solve this problem.
I saw it in a contest conducted on 13 March 8:00PM-11:00PM IST .

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

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

I didn't implement this solution and don't know if this will work or not.

Construct a segment tree where the nodes have a frequency array. Using this type of segment tree we can find the frequencies of all letters in the range [l,r] in $$$O(logN)$$$ time.

Now once we know the frequencies ,we can quickly judge if that sub segment can be re arranged as a palindrome.

If a palindrome is possible, find the compressed version of the palindrome. ( For example the compressed version of this string aaabbccccd will be a:3 b:2 c:4 d:1 ). After you know the compressed version you will have to lazily propagate the changes i.e. new frequencies . Since the length of the compressed string can be at max 53 (palindrome like abcde...yzazy.....dcba) and lazy propagation works in logN , this approach will hopefully pass.

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

    Thanks.

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

    Implemented the same and passed 90% of the testcases rest TLED. But this can be done 100% with this approach.

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

      You will be shocked to know that I used brute force and 90% passed

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

        I think that the testcases were very weak for 5th and 6th problem .

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

          Can u tell your approach for problem 5?

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

            let mx[i] = maximum character in the string s[i....n] Notice that since we need to reverse only 1 substring so we should reverse the string starting at index i and ending at index j , s.t. (s[i]!=mx[i] and s[j]=mx[i] and i<j and i is as small as possible ) Now value of i can be found in O(N) and value of all j's can be found in O(N) as well.
            Time complexity is O(N^2) passed because of Weak TC
            So , now we can check for all j by traversing on the length x of the new string and comparing character which will be at x'th position for the new strings .New string are string formed after reversing substring from i to j .

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

              First I thought of O(n^2) solution but didn't implemented as it would give tle

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

                There is O(NlogN) as well which uses string Hashing and Binary search . Let there be 2 values l,m in the vector containing j , so now we can binary search the first element that differs after reversing s[i...l] and s[i...m] , hash value can be used to check whether string of length mid are equal or not .
                P.S.: This one is what I thought at first , but I just went for O(N^2) solution at first

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

      Were you able to solve the 4th problem ?
      Problem Statement:
      Given a tree consisting of N nodes , find minimum no. of edges to be removed to get atleast one component of size K for all(1<=K<=N).
      1<=N<=1000

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

        I was only able to solve 2 problems with all the test cases passed

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

          How the subsequence with product's unit digit is k would be solved???¿????

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

            It's a Dynamic programming problem , for the ith element there are two option only , either this element can be included or it can't be .
            dp[i][j] denotes no. of subsequences considering first i element that have value at unit digit equal to j .
            Transition are : dp[i+1][(j*(a[i]%10))%10]+=dp[i][j]; (i.e. current element is included )
            dp[i+1][j]+= dp[i][j]; (i.e. current element isn't included )

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

              Hey did you solved that problem in which chalk was to be divided into pieces by k children's in which we had to find the minimized maximum chalk length

              and also for this subsequence with product's unit digit is k can you please provide the code.

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

                Minimum maximum chalk length can be solved by binary search on answers

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

                  I found some of the test cases were giving faulty results. For ex, N = 3 and K = 0 with Arr = { 2 , 6 , 0 } should return value as 6 but the judge was considering value = 3 for such case.

                  Also N = 2 and K = 2 with Arr = {7 , 17} . The return value should be 8 but the judge was expecting 7.

                  I tried using maps but was getting caught up in test cases like this.

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

                  for n = 2 k = 2 a = {7,17} return value is 7. 7,17 7,10,7 (17 = 7+10) k = 1 7,5,5,7 (10 = 5+5) k = 2

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

                They were not allowing to use max heap(priority queue). So I had to use vector & sort it again & again that's why it resulted in TLE. Still, 72% of the test cases passsed.

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

                  U should have just included it's header file . It might have worked .

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

        Yes it can be done by applying dp on the flattened tree.

        First flatten the tree using euler tour and then take dp[i][num_removed] which means we have covered all the subtrees with exit time less than i and total nodes removed is num_removed.
        LHS means Left hand side of the equation

        Like for the first example given there euler tour is something like
        n=6, edges={0,1},{0,2},{2,3},{2,5},{3,4}
        euler tour: 0 1 2 3 4 5
        (here coincidence is in_time is same as node number(not necessary))
        initially

        $$$dp[i][j]=1e9$$$

        for all

        $$$i,j$$$

        initialise

        $$$dp[0][0]=0$$$

        if we take the first subtree at that start at time 0
        then transition

        $$$if(i==0){ add=-1;}$$$

        (I rooted the tree at node 0)}

        $$$dp[i+out_time[node_at[i]]+1][k+sub_t_size[node_at[i]]]=min(LHS,dp[i][k]+1+add);$$$

        if we not cut current subtree that start at time i

        $$$dp[i+1][k]=min(LHS,dp[i][k]);$$$

        and ith ans is

        $$$min(dp[n][i],dp[n][n-i])$$$

        //dp[n-i] is excluded when i=n

        in[],out[] times and node_at[] can be calculated with simple DFS

        70% test cases passed

        The test cases which were not passing because of some validator error like this, incorrect and is shown even when right ans is outputted

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

          What is LHS ?

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

            Plz check the lastest edit and LHS is left hand side

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

              Okkk .
              So in this solution of yours u r considering that if we delete an edge from i->j such that j is a descendent of i , we don't need to delete any other edge in the subtree of j ?

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

                Right if we deleted an edge , that would delete a complete subtree and we won't be able to delete any other edge in the deleted subtree

                And state defining choices are we delete a subtree ofcouse by deleting an edge or not

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

                  Ok , thanks

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

                  Hey plz look at the images in spoiler and
                  can you tell why even correct output is marked incorrect?
                  and
                  one more thing I wanna add is when I downloaded the testcases even they were downloading not the same question

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

                  U returned a vector of size n+1 rather than of the the size n , maybe that's the reason . I have no idea about testcases , I too faced same issue.

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

Can someone help me with this

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

Did anyone get a mail regarding placements from codekaze ? Could you mention your national rank, graduation year and graduation year rank if you did receive a mail regarding placements?

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

is there any way i can test my approach for this and other problem that were asked in the contest.(I cannot took part in the contest but want to upsolve)?.

Thanks in advance.

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

Has anyone received Amazon gift card?

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

    I have not received it yet . I have filled the google form which they have send but not received the voucher till now what should I Do.