I_love_penny's blog

By I_love_penny, history, 11 months ago, In English

Hello I wanted to know how can this java code can be improved. Currently it get TLE in few test cases.It would be helpful if someone can find the bottleneck in this solution.

Problem: https://cses.fi/problemset/task/1192
Solution: find the number of connected components.

code link: https://cses.fi/paste/b4d685acb261aaca26c573/

equivalent code in c++ is 10 times faster than java.

I am trying to switch to java for cp.

Read more »

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

By I_love_penny, history, 5 years ago, In English

In this problem you are given "x" amount of money in currency "s" and you want to maximise the amount in "m" steps to currency "f". cost matrix is given for transfer rate. Sounds similar to finding number of ways to reach from one node to another in k steps. So the answer to problem is (s,f) value of mth power of given cost matrix (exchange rate matrix). we need to modify matrix multiplication accordingly to get maximum cost.

code

But we want ans%mod , this mod will ruin my multiplication of matrix. I will not get maximum. Editorial suggest to use power of primes , can someone please explain that.
Problem Link

Read more »

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

By I_love_penny, history, 5 years ago, In English

How to solve this problem using binary search.
Problem Statement :
You are given an array A of N integers in nondecreasing order. Remove K integers such that the maximum difference between two consecutive elements is minimized.
​​Problem Link
solution using binary search (I am not getting its intuition). ​​

Read more »

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