forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
81 lines (64 loc) · 1.54 KB
/
main.cpp
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
80
81
// Authored by : klm03025
// Co-authored by : -
// Link : http://boj.kr/cf1f9691a2bc4d6795218d266c851386
#include <bits/stdc++.h>
using namespace std;
int dm_len[100][100];
bool dm_alive[100][100];
int N, M, R;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int score = 0;
void offense(int x, int y, char pos) {
int idx;
int dest = 0;
if(pos == 'E') idx = 0;
else if(pos == 'W') idx = 1;
else if(pos == 'S') idx = 2;
else idx = 3;
if(!dm_alive[x][y]) return;
score++;
dm_alive[x][y] = 0;
dest = dm_len[x][y];
while(dest != 1) {
dest--;
x += dx[idx];
y += dy[idx];
if(x == N || x < 0 || y == M || y < 0) break;
if(dm_alive[x][y]) {
dest = max(dm_len[x][y], dest);
score++;
}
dm_alive[x][y] = 0;
}
}
void defense(int x, int y) {
dm_alive[x][y] = 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M >> R;
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
cin >> dm_len[i][j];
dm_alive[i][j] = 1;
}
}
for(int i = 0; i < R; i++) {
int x, y;
char pos;
cin >> x >> y >> pos;
offense(x - 1, y - 1, pos);
cin >> x >> y;
defense(x - 1, y - 1);
}
cout << score << '\n';
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
if(dm_alive[i][j]) cout << 'S' << ' ';
else cout << 'F' << ' ';
}
cout << '\n';
}
}