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

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

Hello guys, Can anyone explain me how to do Problem E . (I came up with a greedy solution where in we sort based on the last candidates and remove first k polls until the sum of last candidate is less than at least one candidate. nut realized it would be wrong.) So can anyone explain a way to do this. Thank you!

I read the editorial and couple of other people's solution, but I couldn't understand what's going on.

Полный текст и комментарии »

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

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

Hello guys,

I was trying to solve Distinct Colors: link.

I did a naive solution which obviously led to TLE.

TLE

I saw various solutions that use BIT. But I cant assimilate why BIT works here, what BIT represents here (for e.g. in case range sum query BIT keeps track of cummulative frequency.)

It would be great if someone tells some trick how to use BIT for various other purposes too.

Thanks!

Полный текст и комментарии »

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

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

Hello guys,

I have been trying to solve Dp problems. When I read a problem I try to translate it into DFS(recursion) which ends up having TLE, then I simply store the state variables so it passes the time limit. But What I want to learn is that, any trick is there to convert this into iterative DP( As I guess DFS+memo has large constant factor).

For example take this problem: link

TLE Code non memoized
DFS+Memo Passed

So I want to learn a generic technique ( not limited to this problem) to write iterative solutions as No matter how hard I try I am unable to grasp iterative writing method. It would be great if you guys could help me in this. Thank you!

P.S. Please Dont downvote this blog guys as some people have extension to hide bad blogs. Once I get an answer you can downvote it to your hearts content. Thanks :)

Полный текст и комментарии »

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

Автор retr0coderxyz, история, 5 лет назад, По-английски

Hello guys,

When I was practicing problems found that there was no way to hide the problem tags. It really hinders my ability to identify the class of problem. So I wrote an extension for chrome to hide the tags and reveal when required. It is quite useful for me and I guess you guys would also feel its useful.

Link for extension: link

Instructions: link

Use the extension and let me if you guys face any bugs or any sorts of thing.

UPD: well this extension allows to reveal tags in a button press. So after long time if we are unable to identify the class of problem we can simple reveal it. I find it much easier than turning entirely off in settings. Hope i gave back something meaningful for this beautiful community.

UPD2 Screenshots:

1.png

2.png

Thank you and happy coding.

Полный текст и комментарии »

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

Автор retr0coderxyz, история, 5 лет назад, По-английски

Hey guys!

I am trying to solve Qtree2 from SPOJ after learning about LCA using binary lifting.Problem

There are 2 parts to this question one is to find distance between any two given nodes and the other part is to find kth node in the path between 2 nodes.

While I was able to solve the first part, but I am stuck in solving second part, I tried a lot (only clue i was able to find out is that the path goes through LCA of two nodes) and couldn't proceed from there.

It would be really helpful if someone could give a detailed explanation using binary lifting it would be great. Thank you so much!

Полный текст и комментарии »

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

Автор retr0coderxyz, история, 5 лет назад, По-английски

Can anyone tell me how to solve this problem: 208E.

I saw few solutions and I understood till the LCA part I dont understand why should we renumber the tree and why is binary search used here. It would be great if anybody could help me out with this. Please and thank you so much :)

Полный текст и комментарии »

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

Автор retr0coderxyz, история, 5 лет назад, По-английски

Hello Community,

I am trying to learn to find LCA using binary lifting method. But, I am unable to find where does my code fail. It would be great if someone could point this out.

Problem: LCA

Solution: Solution

Please Help me with this guys ! Please. Thank you!

Полный текст и комментарии »

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

Автор retr0coderxyz, история, 5 лет назад, По-английски

Hello guys,

https://codeforces.net/contest/1324/submission/73157058 fails at test 99 because of this

error

But this works fine in local compiler for the same test case. can anybody point out my mistake?

Thanks!

Полный текст и комментарии »

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

Автор retr0coderxyz, история, 5 лет назад, По-английски

Hello community,

Recently I cam across 4 questions(A hiring challenge from Hacker Earth which is over now!) to which I could not find solutions. I tried my best during contest to come with solutions but I was unable to do so. It would be great if you guys could help me provide a solution for these problems(also a generic solution for similar kind of problems) Would really help me a lot. I dont remember the exact problem but I would try to provide the best description to my knowledge.

Problem 1:

We have to distribute N coins to S students such that each gets distinct number of coins while maximizing S. We have to find S. For eg. if N is 5 then S is 2 because (2,3). Its not mandatory to distribute all N coins.

My Idea

Problem 2:

Swapping the segments: given array of size n and q queries with each query containing l1,r1,l2,r2 A[l1:r1] should be swapped with A[l2,r2] After Q queries we should print the final array.

My Idea

Problem 3:

Given a string s we need to find two subsequence s1=s2 and maximize |s1+s2|. For eg: aabababb the answer is 6 s1=aab and s2=aab

My Idea

Problem 4:

Given a character for each node. and given a graph(its guarenteed to be a tree). Q queries with each query giving x y. We have to find for each query a consider a simple path from x->y find the most frequent character along the path. For eg.

6
a b a s q n
(n-1 edges)
1 2
1 3
2 6
3 4
3 5
2
2 3  => a
2 6  => b(print lexicographically smaller in case of tie)
My Idea

Thank you for reading patiently guys, I tried so much to come up with a solution but couldnt so any help would be greatly appreciated guys.

Полный текст и комментарии »

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