Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years. ×

### Mr.Awesome's blog

By Mr.Awesome, history, 2 months ago, ,

Here's a problem I crossed lately:

You have a large String S, and q queries, each query consist of a small string b.

The answer of each query is to find the length of the longest common substring between S and b. ( |S| <= 10^5, |b| <= 100, q <= 100 )

My dp solution to find the length of the largest LCS is O(n*m) per query, but it doesn't seem to pass!

I think will need to do some pre-prcessing of S before starting quering, but I can't find a solution.

Any hint or idea will be appreciated.

Read more »

• +4

By Mr.Awesome, history, 3 years ago, ,

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 »

• 0

By Mr.Awesome, history, 3 years ago, ,

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 »

• +1

By Mr.Awesome, history, 3 years ago, ,

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 »

• -8

By Mr.Awesome, history, 3 years ago, ,

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 »

• 0

By Mr.Awesome, history, 4 years ago, ,

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 »

• +8

By Mr.Awesome, history, 4 years ago, ,

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 »

• 0

By Mr.Awesome, history, 4 years ago, ,

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 »

• 0