-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathJava.java
79 lines (67 loc) · 2.43 KB
/
Java.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/****************************************/
/* */
/* CodinGame.com Solutions by pathosDev */
/* */
/* Puzzle: Lumen */
/* Difficulty: Easy */
/* Date solved: 22.02.2019 */
/* */
/****************************************/
import java.util.Scanner;
public class Solution
{
public static void main(String[] args)
{
//Read inputs.
Scanner scanner = new Scanner(System.in);
int N = Integer.parseInt(scanner.nextLine());
int L = Integer.parseInt(scanner.nextLine());
int[][] grid = new int[N][N];
//Read and create initial grid.
for (int x = 0; x < N; x++)
{
String[] line = scanner.nextLine().split(" ");
for (int y = 0; y < N; y++)
{
grid[x][y] = line[y].equals("C") ? L : 0;
}
}
//Add dimmed spots, so everything 0<x<L.
for (int i = L - 1; i > 0; i--)
{
for (int x = 0; x < N; x++)
{
for (int y = 0; y < N; y++)
{
//Find biggest surrounding cell.
int max_surrounding_cell = 0;
for (int x_step = -1; x_step <= 1; x_step++)
{
for (int y_step = -1; y_step <= 1; y_step++)
{
if(0 <= x + x_step && x + x_step < N && 0 <= y + y_step && y + y_step < N)
{
max_surrounding_cell = Math.max(max_surrounding_cell, grid[x + x_step][y + y_step]);
}
}
}
//Dimmed spot on (x, y) is the maximum in the surrounding cells minus one.
grid[x][y] = Math.max(grid[x][y], max_surrounding_cell - 1);
}
}
}
//Count dark spots and print the result.
int darkSpots = 0;
for (int x = 0; x < N; x++)
{
for (int y = 0; y < N; y++)
{
if (grid[x][y] == 0)
{
darkSpots++;
}
}
}
System.out.println(darkSpots);
}
}