Submission details
Task:Maalaus
Sender:20mins
Submission time:2025-11-08 15:01:53 +0200
Language:Java
Status:COMPILE ERROR

Compiler report

input/Main.java:56: error: bad operand types for binary operator '<='
            if  (1 <= rowcolor <= k) {
                               ^
  first type:  boolean
  second type: int
input/Main.java:74: error: bad operand types for binary operator '<='
            if ( 1 <= columncolor <= k) {
                                  ^
  first type:  boolean
  second type: int
2 errors

Code

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int k = scanner.nextInt();
        int q = scanner.nextInt();
        scanner.nextLine();

        Map<Integer, int[]> rows = new HashMap<>();
        Map<Integer, int[]> columns = new HashMap<>();
        
        for (int time = 1; time <= q; time++) {
            String[] op = scanner.nextLine().split("\\s+");
            String type = op[0];
            int index = Integer.parseInt(op[1]) - 1;
            int color = Integer.parseInt(op[2]);

            if (type.equals("R")) {
                rows.put(index, new int[]{time, color});
            } else if (type.equals("C")) {
                columns.put(index, new int[]{time, color});
            }
        }

        List<Integer> rowtimes = new ArrayList<>();
        for (int[] data : rows.values()) {
            rowtimes.add(data[0]);
        }

        List<Integer> columntimes = new ArrayList<>();
        for (int[] data : columns.values()) {
            columntimes.add(data[0]);
        }

        int unpaintedrows = n - rows.size();
        int unpaintedcolumns = m - columns.size();

        long[] color_counts = new long[k + 1];
        for (int[] rowData : rows.values()) {
            int rowtime = rowData[0];
            int rowcolor = rowData[1];

            int columnless = 0;
            for (int columntime : columntimes) {
                if (columntime < rowtime) {
                    columnless++;
                }
            }

            int totalcells = columnless + unpaintedcolumns;

            if  (1 <= rowcolor <= k) {
                color_counts[rowcolor] += totalcells;
            }
        }

        for (int[] colData : columns.values()) {
            int columntime = colData[0];
            int columncolor = colData[1];

            int rowless = 0;
            for (int rowtime : rowtimes) {
                if (rowtime < columntime) {
                    rowless++;
                }
            }

            int totalcells = rowless + unpaintedrows;

            if ( 1 <= columncolor <= k) {
                color_counts[columncolor] += totalcells;
            }
        }

        StringBuilder result = new StringBuilder();
        for (int i = 1; i <= k; i++) {
            result.append(color_counts[i]);
            if (i < k) result.append(" ");
        }

        System.out.println(result);
    }
}