SHARE
TWEET

Untitled

a guest Jun 9th, 2019 13 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. In the nation of CodeWars, there lives an Elder who has lived for a long time. Some people call him the Grandpatriarch, but most people just refer to him as the Elder.
  2.  
  3. There is a secret to his longetivity: he has a lot of young worshippers, who regularly perform a ritual to ensure that the Elder stays immortal:
  4.  
  5. - The worshippers lines up in a magic rectangle, of dimensions m and n.
  6. - They channel their will to wish for the Elder. In this magic rectangle, any worshipper can donate time equal to the xor of the column and the row (zero-indexed) he's on, in seconds, to the Elder.
  7.  
  8. - However, not every ritual goes perfectly. The donation of time from the worshippers to the Elder will experience a transmission loss l (in seconds). Also, if a specific worshipper cannot channel more than l seconds, the Elder will not be able to receive this worshipper's donation.
  9. - The estimated age of the Elder is so old it's probably bigger than the total number of atoms in the universe. However, the lazy programmers (who made a big news by inventing the Y2K bug and other related things) apparently didn't think thoroughly enough about this, and so their simple date-time system can only record time from 0 to t-1 seconds. If the elder received the total amount of time (in seconds) more than the system can store, it will be wrapped around so that the time would be between the range 0 to t-1.
  10.  
  11. Given m, n, l and t, please find the number of seconds the Elder has received, represented in the poor programmer's date-time system.
  12.  
  13. (Note: t will never be bigger than 2^32 - 1, and in JS, 2^26 - 1.)
  14.  
  15.  
  16. EXAMPLE
  17. m=8, n=5, l=1, t=100
  18.  
  19. Let's draw out the whole magic rectangle:
  20. 0 1 2 3 4 5 6 7
  21. 1 0 3 2 5 4 7 6
  22. 2 3 0 1 6 7 4 5
  23. 3 2 1 0 7 6 5 4
  24. 4 5 6 7 0 1 2 3
  25.  
  26. Applying a transmission loss of 1:
  27. 0 0 1 2 3 4 5 6
  28. 0 0 2 1 4 3 6 5
  29. 1 2 0 0 5 6 3 4
  30. 2 1 0 0 6 5 4 3
  31. 3 4 5 6 0 0 1 2
  32.  
  33. Adding up all the time gives 105 seconds.
  34.  
  35. Because the system can only store time between 0 to 99 seconds, the first 100 seconds of time will be lost, giving the answer of 5.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top