Mr.Awesome's blog

By Mr.Awesome, history, 11 months ago, In English,

I was trying to solve this problem, after submitting my solution I got TLE and I couldn't figure out the problem with my O(n.log(n)) solution, I also checked some accepted solution and most of them are using the same approach?

my submission

UPD

I got accepted by copying someone sort function but I still want to know what's wrong with java.util.Arrays.sort function?

Read more »

 
 
 
 

By Mr.Awesome, history, 11 months ago, In English,

I was checking some solution of this problem, and I didn't understand 2 things, let's look at this solution , first why we loop over k j(0..k), and second why k replaced by j and k-j in each call?

Read more »

Tags dp
 
 
 
 
  • Vote: I like it  
  • +1
  • Vote: I do not like it  

By Mr.Awesome, history, 13 months ago, In English,

I was trying to solve this problem but i got TLE.

In short terms the problem is :

You are given m queries each contains three integers l,r,x, (l<=x<=r) and you have to fill segment [l,r] with integer x except for the element of indices x, ex. if l=1,r=3 and x=2 segment [l,r] = {2,0,2}.

My solution use an indicator array called nxt to avoid filling the already visited segments and go to the next unvisited item, so this should be done in O(n), however i'm getting a TLE and i can't figure out why.

this is my submission

any help or hint is very appreciated.

Read more »

 
 
 
 
  • Vote: I like it  
  • -8
  • Vote: I do not like it  

By Mr.Awesome, history, 15 months ago, In English,

Hi everyone.

Lets suppose that we have an array with differents elements, and a function f(x,y) that takes 2 elements from the array and return true or false..

We want to extract all connected components.

Note that if f(x,y) = true and f(y,z) = true then x,y,z are in the same connected component even though f(x,z) = false

My simple solution is to iterate over each pair(x,y) and connect vertex with value x to a vertex with value y if f(x,y) = true , and then extract all connected components.

The complexity of this solution is O(n^2) , However i'm looking for a better solution. Thanks.

UDP I guess i didn't explain well, so here an example :

Lets a be an array : a = { 1 , 4 , 7 , 5 , 9 }

f(1,4)=true , f(1,7)=false , f(1,5)=false , f(1,9)=false f(4,7)=false , f(4,5)=false , f(4,9)=true f(7,5)=true , f(7,9)=false f(5,9)=false

So the answer will be 2 sets ( 1,4,9 ) and (7,5)

Note that f(x,y)=f(y,x)

N=1e5

Read more »

 
 
 
 

By Mr.Awesome, history, 20 months ago, In English,

Hi CF's .

Is there any algorithm that can find the biggest Complete graph inside a graph.

I searched a little but i didn't find any resources , is such algorithm even exist ?

Read more »

 
 
 
 
  • Vote: I like it  
  • +8
  • Vote: I do not like it  

By Mr.Awesome, history, 22 months ago, In English,

hi CF community. I was trying to solve this problem but i got a TLE.

My backtrack approach use bitmask to mark treasures already taken .

the constraints of the problem are small so i didn't figure out why it gives TLE .

here my commented code .

Read more »

 
 
 
 

By Mr.Awesome, history, 2 years ago, In English,

I'm getting WA in this 449B this is my submission

i implemented the dijkstra's algorithm to find shortest path between the capital and each city , and the result is stored in dist[] .

could anyone point out the problem , or tell me if my idea is wrong ??

Read more »