Skip to content

Commit 4a45990

Browse files
committed
Add Codeforces 254
1 parent 95f302b commit 4a45990

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Codeforces/Round254/A/A.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import java.util.Scanner;
2+
3+
public class A {
4+
static int n, m;
5+
static char[][] field;
6+
7+
public static void main(String[] args) {
8+
Scanner sc = new Scanner(System.in);
9+
n = sc.nextInt();
10+
m = sc.nextInt();
11+
field = new char[n][m];
12+
for (int i = 0; i < n; i++)
13+
field[i] = sc.next().toCharArray();
14+
for (int i = 0; i < n; i++)
15+
for (int j = 0; j < m; j++)
16+
if (field[i][j] == '.')
17+
search(j, i, 'B');
18+
for (int i = 0; i < n; i++) {
19+
for (int j = 0; j < m; j++)
20+
System.out.print(field[i][j]);
21+
System.out.println();
22+
}
23+
sc.close();
24+
}
25+
26+
static void search(int x, int y, char c) {
27+
int[] dx = { -1, 0, 1, 0 };
28+
int[] dy = { 0, -1, 0, 1 };
29+
field[y][x] = c;
30+
for (int i = 0; i < dx.length; i++) {
31+
if (isIn(x + dx[i], y + dy[i])
32+
&& field[y + dy[i]][x + dx[i]] == '.') {
33+
if (c == 'B')
34+
search(x + dx[i], y + dy[i], 'W');
35+
else
36+
search(x + dx[i], y + dy[i], 'B');
37+
}
38+
}
39+
}
40+
41+
static boolean isIn(int x, int y) {
42+
return x >= 0 && x < m && y >= 0 && y < n;
43+
}
44+
}

0 commit comments

Comments
 (0)