Submission #60529908


Source Code Expand

Copy
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int H = in.nextInt();
int W = in.nextInt();
int D = in.nextInt();
in.nextLine();
char[][] grid = new char[H][W];
for (int i = 0; i < H; i++) {
grid[i] = in.nextLine().toCharArray();
}
int[] dx = {0, 0, -1, 1};
int[] dy = {-1, 1, 0, 0};
boolean[][] see = new boolean[H][W];
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import java.util.*;

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

        int H = in.nextInt();
        int W = in.nextInt();
        int D = in.nextInt();
        in.nextLine();

        char[][] grid = new char[H][W];
        for (int i = 0; i < H; i++) {
            grid[i] = in.nextLine().toCharArray();
        }

        int[] dx = {0, 0, -1, 1};
        int[] dy = {-1, 1, 0, 0};

        boolean[][] see = new boolean[H][W];

        Queue<int[]> queue = new LinkedList<>();

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (grid[i][j] == 'H') {
                    queue.add(new int[]{i, j, 0}); 
                    see[i][j] = true;
                }
            }
        }

        int count = 0;




















        

        while (!queue.isEmpty()) {
            int[] cell = queue.poll();
            int x = cell[0];
            int y = cell[1];
            int len = cell[2];

            if (grid[x][y] == '.' || grid[x][y] == 'H') {
                count++;
                //grid[x][y] = '#';

            }
            if (len == D) continue;

            for (int k = 0; k < 4; k++) {
                int nx = x + dx[k];
                int ny = y + dy[k];

                if (nx >= 0 && nx < H && ny >= 0 && ny < W && !see[nx][ny] && grid[nx][ny] != '#') {
                    queue.add(new int[]{nx, ny,len + 1});
                    see[nx][ny] = true;
                }
            }
        }

        System.out.println(count);
    }
}

Submission Info

Submission Time
Task C - Humidifier 3
User pitch_black
Language Java (OpenJDK 17)
Score 350
Code Size 1674 Byte
Status AC
Exec Time 306 ms
Memory 77760 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 39
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 73 ms 38292 KB
00_sample_02.txt AC 73 ms 37896 KB
00_sample_03.txt AC 75 ms 37932 KB
01_test_01.txt AC 280 ms 76948 KB
01_test_02.txt AC 286 ms 76384 KB
01_test_03.txt AC 285 ms 77452 KB
01_test_04.txt AC 294 ms 76660 KB
01_test_05.txt AC 296 ms 76780 KB
01_test_06.txt AC 306 ms 76684 KB
01_test_07.txt AC 303 ms 77760 KB
01_test_08.txt AC 297 ms 76744 KB
01_test_09.txt AC 301 ms 76908 KB
01_test_10.txt AC 297 ms 75860 KB
01_test_11.txt AC 177 ms 44032 KB
01_test_12.txt AC 148 ms 45700 KB
01_test_13.txt AC 99 ms 39652 KB
01_test_14.txt AC 107 ms 40584 KB
01_test_15.txt AC 165 ms 46528 KB
01_test_16.txt AC 177 ms 50536 KB
01_test_17.txt AC 181 ms 48740 KB
01_test_18.txt AC 285 ms 64144 KB
01_test_19.txt AC 232 ms 63736 KB
01_test_20.txt AC 102 ms 40532 KB
01_test_21.txt AC 180 ms 49960 KB
01_test_22.txt AC 200 ms 50764 KB
01_test_23.txt AC 200 ms 50080 KB
01_test_24.txt AC 198 ms 49472 KB
01_test_25.txt AC 203 ms 49936 KB
01_test_26.txt AC 200 ms 50304 KB
01_test_27.txt AC 198 ms 50280 KB
01_test_28.txt AC 200 ms 51256 KB
01_test_29.txt AC 72 ms 38180 KB
01_test_30.txt AC 71 ms 37904 KB
01_test_31.txt AC 72 ms 37828 KB
01_test_32.txt AC 70 ms 38176 KB
01_test_33.txt AC 238 ms 60400 KB
01_test_34.txt AC 268 ms 62748 KB
01_test_35.txt AC 262 ms 62524 KB
01_test_36.txt AC 277 ms 62832 KB


2025-03-25 (Tue)
09:35:40 +00:00