Skip to content

Commit abc326e

Browse files
authored
[20250323] BOJ / G5 / 인내의 도미노 장인 호석 / 이강현
1 parent a808c02 commit abc326e

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
public class Main {
5+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
6+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
7+
static StringTokenizer st;
8+
static int N = 0; // 행 개수
9+
static int M = 0; // 열 개수
10+
static int R = 0; // 라운드 횟수
11+
static int[][] board; //게임판
12+
static boolean[][] state;
13+
static int[] di = {0,0,1,-1};
14+
static int[] dj = {1,-1,0,0};
15+
static int answer = 0; // 총 쓰러트린 개수
16+
public static void main(String[] args) throws Exception {
17+
st = new StringTokenizer(br.readLine());
18+
N = Integer.parseInt(st.nextToken());
19+
M = Integer.parseInt(st.nextToken());
20+
R = Integer.parseInt(st.nextToken());
21+
board = new int[N+1][M+1];
22+
state = new boolean[N+1][M+1];
23+
24+
for(int i=1;i<=N;i++){ //배열 초기화
25+
st = new StringTokenizer(br.readLine());
26+
for(int j=1;j<=M;j++) {
27+
board[i][j] = Integer.parseInt(st.nextToken());
28+
}
29+
}
30+
31+
for(int i=0;i<R;i++){ //라운드 반복
32+
/*공격*/
33+
st = new StringTokenizer(br.readLine());
34+
int X = Integer.parseInt(st.nextToken());
35+
int Y = Integer.parseInt(st.nextToken());
36+
String D = st.nextToken();
37+
38+
if(D.equals("E")){ //
39+
answer += attack(X,Y,0);
40+
}else if(D.equals("W")){//
41+
answer += attack(X,Y,1);
42+
}else if(D.equals("S")){//
43+
answer += attack(X,Y,2);
44+
}else if(D.equals("N")){//
45+
answer += attack(X,Y,3);
46+
}
47+
48+
/*수비*/
49+
st = new StringTokenizer(br.readLine());
50+
X = Integer.parseInt(st.nextToken());
51+
Y = Integer.parseInt(st.nextToken());
52+
state[X][Y] = false;
53+
}
54+
bw.write(answer+"\n");
55+
for(int i=1;i<=N;i++){
56+
for(int j=1;j<=M;j++){
57+
if(state[i][j]){
58+
bw.write("F ");
59+
}else{
60+
bw.write("S ");
61+
}
62+
}
63+
bw.write("\n");
64+
}
65+
bw.close();
66+
}
67+
public static int attack(int i, int j, int direction){
68+
int total = 0;
69+
if(!state[i][j]){
70+
state[i][j] = true;
71+
total++;
72+
for(int k=1;k<board[i][j];k++){
73+
int newi = i + di[direction]*k;
74+
int newj = j + dj[direction]*k;
75+
if(newi<=0 || newi>N || newj<=0 || newj>M) continue;
76+
total += attack(newi,newj,direction);
77+
}
78+
}
79+
return total;
80+
}
81+
}
82+
83+
```

0 commit comments

Comments
 (0)