From 8c5ac774d2d14605ebe6dedbbce126a12300fcb3 Mon Sep 17 00:00:00 2001 From: dadgam3er Date: Fri, 13 Sep 2024 17:21:57 -0400 Subject: [PATCH] anotherOne --- OneDArray.class | Bin 0 -> 1089 bytes OneDArray.java | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 OneDArray.class create mode 100644 OneDArray.java diff --git a/OneDArray.class b/OneDArray.class new file mode 100644 index 0000000000000000000000000000000000000000..a87ee23f8383f6f1bd9770f34cf9a6c0ac3e9cf3 GIT binary patch literal 1089 zcmZuvT~8B16g|`Zn0EUC6biI#<`=CH&s9!T* zo5`H%tR~aTYgV?zppM&)U7BQ&V(~c*Zg@B}AH47}c+!sb;9jw4ZW1nQI?ru~fyazR z!-y|%1Q;5s1-l1C8~sGsxR$A(s0(xrA(=4 znfWmdel!cMEex%(OCds}A7LLNXd^L>^`>Mvw+}O_Q z*s0V(ACjW?N;X&6uo&d~g%t{QGqz*Rmh;P2@tL`tqZ5CoWM*GIHrH!=Id6(iHOCfD z8*#BTM~YNka>a3n3@jQPqZiv>6~&-s3gu$fdT0yI!2cf}6b8{r1K^_30c4P5sI(5z zE=rM6R0a;gK2ySQomO!TNbrbxp1zBmF(Jggz*Lgd*+f@>1et2VOlw@e>qz zFQLon2rVl|;O`I?=~6WfP#O{GHn_YCS=ys&t}0(2F$q>LI1Pb^WNBze0NrT7FoKw* zp))AIK`0H}%j#H= game.length || index + leap >= game.length) { + return true; + } + + // Mark current position as visited + game[index] = 1; + + // Recursive cases + return canWin(leap, game, index - 1) || // Move backward + canWin(leap, game, index + 1) || // Move forward + canWin(leap, game, index + leap); // Jump forward + } + + public static boolean canWin(int leap, int[] game) { + return canWin(leap, game, 0); // Start from index 0 + } + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int q = scan.nextInt(); + while (q-- > 0) { + int n = scan.nextInt(); + int leap = scan.nextInt(); + int[] game = new int[n]; + for (int i = 0; i < n; i++) { + game[i] = scan.nextInt(); + } + System.out.println((canWin(leap, game)) ? "YES" : "NO"); + } + scan.close(); + } +}