Help with USACO 2021 December Bronze WalkingHome

Hi all,

I have just begun practicing for USACO. While reviewing this problem (Walking Home) I encountered some errors. Can somebody let me know where I went wrong? (When inputting my solutions as a txt file in the usaco website the website gave me a compilation error but did not specific what the specific error is).
Thanks in advance.
EDIT: Here is the problem page link: USACO
Here is my code:

import java.io.*;
import java.util.StringTokenizer;

class WalkingHome {
public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);

	StringTokenizer aoeu = new StringTokenizer(r.readLine());
	int total = Integer.parseInt(aoeu.nextToken());
	for(int aoneuthaosnueth = 0; aoneuthaosnueth< total; aoneuthaosnueth++) {
	StringTokenizer st1 = new StringTokenizer(r.readLine());
	int n = Integer.parseInt(st1.nextToken());
	int k = Integer.parseInt(st1.nextToken());
	int[][] array = new int[n][n];
	for(int i = 0; i < n; i++) {
	StringTokenizer st = new StringTokenizer(r.readLine());
		String currRow = st.nextToken();
		for(int j = 0; j < n; j++) {
			if(currRow.charAt(j) == 'H') array[i][j] = 1;
		}
	}
	
	pw.println(func(array, 0, 0, k, 'a'));

	pw.close();
}
public static int func(int[][] arr, int row, int col, int movesLeft, char lastMove) {
	if(row == arr.length - 1 || col == arr.length - 1) {
		return 1;
	}
	int sum = 0;
	if(movesLeft < 0) return 0;
	if(lastMove == 'r') {
		for(int i = row+1; i < arr.length; i++) {
			sum += func(arr, i, col, movesLeft - 1, 'd');
		}
		for(int j = col+1; j < arr.length; j++) {
			sum += func(arr, row, j, movesLeft, 'r');
		}
	}
	if(lastMove == 'd') {
		for(int i = row+1; i < arr.length; i++) {
			sum += func(arr, i, col, movesLeft, 'd');
		}
		for(int j = col+1; j < arr.length; j++) {
			sum += func(arr, row, j, movesLeft - 1, 'r');
		}
	}
	else {
		for(int i = row+1; i < arr.length; i++) {
			sum += func(arr, i, col, movesLeft, 'd');
		}
		for(int j = col+1; j < arr.length; j++) {
			sum += func(arr, row, j, movesLeft, 'r');
		}
	}

	return sum;
}

}

Hmmm… This is a tough one… I am stumped…

Are you submitting in Java? What is the name of the file you are submitting? What error message are you getting? I get the following when submitting as WalkingHome.java:

1 Like

Sorry for the late reply. Thanks, I believe submitting as WalkingHome.java works.