Vassil_Iliev

kangoroo

Mar 30th, 2022
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let input = [
  2.     '6 7 3',
  3. '0 0',
  4. '2 2',
  5. '-2 2',
  6. '3 -1'
  7. ];
  8.  
  9. let print = this.print || console.log;
  10. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  11.  
  12. const line1 = gets().split(' ').map(Number);
  13. const rows = line1[0];
  14. const cols = line1[1];
  15. const countJumps = line1[2];
  16. const line2 = gets().split(' ').map(Number);
  17. let curRow = line2[0];
  18. let curCol = line2[1];
  19. let arrMoves = []
  20.  
  21. for(let i = 0; i < countJumps;i++){
  22. arrMoves.push(gets().split(' ').map(Number))
  23. }
  24.  
  25. let index = 1;
  26. let matrix = [];
  27. let jumps = 0;
  28. let arrCollected = [];
  29. let sumOfCollected = 0;
  30.  
  31. for(let i = 0; i<rows;i++){
  32.     matrix[i]=[]
  33.     for(let j = 0; j<cols;j++){
  34.         matrix[i][j]=index++
  35.     }
  36. }
  37. let counter = 0
  38.  
  39. outer:
  40. while(true){
  41.  
  42.     if(curRow< 0 || curCol< 0 || curRow >= rows || curCol>= cols){
  43.             jumps++
  44.             print(`escaped ${sumOfCollected}`)
  45.             break outer;
  46.         }else if(arrCollected.includes(matrix[curRow][curCol])){
  47.             jumps++
  48.             print(`caught ${jumps}`)
  49.             break outer;
  50.         }else{
  51.             arrCollected.push(matrix[curRow][curCol]);
  52.             sumOfCollected +=matrix[curRow][curCol]
  53.             jumps++;
  54.             curRow = curRow + arrMoves[counter][0]
  55.             curCol = curCol + arrMoves[counter][1]
  56.         }
  57.    
  58.         if(counter < arrMoves.length-1){
  59.         counter++
  60.     }else{
  61.         counter = 0;
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment