waidfj's blog

By waidfj, history, 93 minutes ago, In English

I am struggling with a small issue in 2271C - XOR Problem of today's contest.

For n = 2, my code gave this array as output: [2, 1, 0, 2, 0, 1, 2] and it passed the judge's test. However, I just read the expected answer [0, 2, 0, 1, 0, 2, 0] and now I think that my output should've gotten wrong.

Looking at the expected answer, it has a length of 7 and 0 subarrays, and thus the beauty of it is 7. But in my array its length is 7 and it has 2 subbarrays ([2, 1, 0, 2, 0, 1] and [1, 0, 2, 0, 1, 2]) which gives it a beauty of 5, which is not the maximum, which means it's wrong.

Can someone please help me understand if I'm missing something, why was my array judged accurate? 394017566

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By waidfj, history, 3 weeks ago, In English

Hello! I was studying Josephus Problem (in a circle of n people, each round the kth person is killed until one person is left, find out who survives)

I am aware of the O(n) solution, the recursive and the iterative solutions. I understand that the survivor of the circle is obtained from getting the survivor of the smaller cicle and adjusted by k positions.

However I just found the O(klogn) solution on cp algorithms. I understand that we are skipping n/k steps when k is less than n to save time but I don't understand how is the value of it is adjusted to give the answer for the current circle size?

Would someone be able to help me on this point please?

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it