CSES - Datatähti 2016 alku - Results
Submission details
Task:Tontti
Sender:Galax
Submission time:2015-10-01 09:07:55 +0300
Language:Java
Status:COMPILE ERROR

Compiler report

input/Main.java:60: error: method iterateThroughAllSquares in class Main cannot be applied to given types;
            iterateThroughAllSquares(width, height, size-1, woods, trees, hits);
            ^
  required: int,int,int,ArrayList<String>,int
  found: int,int,int,ArrayList<String>,int,int
  reason: actual and formal argument lists differ in length
1 error

Code

import java.util.ArrayList;
import java.util.HashMap;
public class Main {
   
    //change arraylists to strings, as they present single lines of text, the row number functions as
    //the key. you need to change all the function calls and shit.
    private static int hits;
    public static void main(String[] args) {
        IO io = new IO();
        int height = io.nextInt();
        int width = io.nextInt();
        int trees = io.nextInt();
        hits = 0;
        
      //  HashMap<Integer,ArrayList<String>> woods = new HashMap<>();
        ArrayList<String> woods = new ArrayList<>();
        
        for (int i = 0; i < height; i++) {
            woods.add(io.next());
        }
        int smallest = height;
        if (height > width) {
            smallest = width;
        }
        
        iterateThroughAllSquares(width,height,smallest, woods, trees);

        
        io.println(hits);
        io.close();
    }
    private static void searchSquare(int startx, int starty, int size, 
        ArrayList<String> woods, int trees) {
        
        int temphits = 0;
        for (int i = startx; i < size; i++) {
            for (int j = starty; j < size; j++) {
                if (woods.get(j).charAt(i)=='*') {
                    temphits++;
                }
            }
        }
        if (temphits==trees) {
            hits++;
        }
        System.out.println(hits);
    }
    //in this function, the grid starts from 0,0 in the left upper corner
    private static void iterateThroughAllSquares(int width, int height, int size,
            ArrayList<String> woods, int trees) {
        for (int i = 0; i <= width-size; i++) {
            for (int j = 0; j <= height-size; j++) {
                searchSquare(i, j, size, woods, trees);
                
            }
        }
        //calls itself here
        if (size*size >= trees) {
            iterateThroughAllSquares(width, height, size-1, woods, trees, hits);
        }
    }
}