fork download
  1. public class MovingCandies {
  2. int h, w;
  3. String[] input;
  4. boolean[][][][] vis;
  5. void dfs(int row, int col, int len, int ones) {
  6. if(!order(0, row, h - 1) || !order(0, col, w - 1))
  7. return;
  8. ++len;
  9. if(input[row].charAt(col) == '#')
  10. ++ones;
  11. if(len > h * w || vis[row][col][len][ones])
  12. return;
  13. vis[row][col][len][ones] = true;
  14. dfs(row + 1, col, len, ones);
  15. dfs(row, col + 1, len, ones);
  16. dfs(row - 1, col, len, ones);
  17. dfs(row, col - 1, len, ones);
  18. }
  19. public int minMoved(String[] t) {
  20. input = t;
  21. h = t.length;
  22. w = t[0].length();
  23. vis = new boolean[h][w][h*w+1][h*w+1];
  24. dfs(0, 0, 0, 0);
  25. int allowed = 0; // the total number of ones in the grid
  26. for(String row : t)
  27. for(int i = 0; i < row.length(); ++i)
  28. if(row.charAt(i) == '#')
  29. ++allowed;
  30. System.out.println(allowed);
  31. final int INF = 1000123;
  32. int ans = INF;
  33. for(int len = 0; len <= allowed; ++len)
  34. for(int ones = 0; ones <= h * w; ++ones)
  35. if(vis[h-1][w-1][len][ones])
  36. ans = min(ans, len - ones);
  37. if(ans == INF)
  38. ans = -1;
  39. return ans;
  40. }
  41. }
  42.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class MovingCandies is public, should be declared in a file named MovingCandies.java
public class MovingCandies {
       ^
Main.java:6: error: cannot find symbol
		if(!order(0, row, h - 1) || !order(0, col, w - 1))
		    ^
  symbol:   method order(int,int,int)
  location: class MovingCandies
Main.java:6: error: cannot find symbol
		if(!order(0, row, h - 1) || !order(0, col, w - 1))
		                             ^
  symbol:   method order(int,int,int)
  location: class MovingCandies
Main.java:36: error: cannot find symbol
					ans = min(ans, len - ones);
					      ^
  symbol:   method min(int,int)
  location: class MovingCandies
4 errors
stdout

Standard output is empty