osource's blog

By osource, history, 3 months ago, In English

let's say I have 2 numbers x and y. How do I check if x*y results in an overflow in C++?. Both x and y are long long int.

Read more »

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

By osource, history, 4 months ago, In English

Hello,

I was solving CSES problemset and am stuck in this question — Question My code — Code

I am getting TLE on 4 test cases. I'm not able to figure out why as I have used standard BFS and therefore the time complexity should be O(m*n). Can someone help me in this?

Read more »

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

By osource, history, 5 months ago, In English

You have 2 arrays A and B each of size n, that contains integers from 1 to n inclusive. In one move, you can swap corresponding elements of two arrays. Determine if it is possible to have such series of operations (possibly zero) that both arrays contain integers from 1 to n exactly once, if possible print the series of operations (ie indices on which you apply the operations) and -1 if not possible.

eg

A = 3 1 2 1 2

B = 5 4 4 5 3

ans = 3 4

explanation :

after operations

A = 3 1 4 5 2

B = 5 4 2 1 3

Can someone tell me the approach/pseudocode for this?

Read more »

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