1
- // Authored by : BaaaaaaaaaaarkingDog
2
- // Co-authored by : -
3
- // http://boj.kr/****************
1
+ // Authored by : qhsl1213
2
+ // Co-authored by : BaaaaaaaaaaarkingDog
3
+ // http://boj.kr/2adb444701754f48baa8b965bb9a9b05
4
4
#include < bits/stdc++.h>
5
5
using namespace std ;
6
+ int canExtend[1000 ][1000 ];
7
+ int step[10 ];
8
+ int area[10 ];
9
+ int dx[4 ] = {0 , 0 , 1 , -1 };
10
+ int dy[4 ] = {1 , -1 , 0 , 0 };
11
+ queue<tuple<int , int , int >> q[10 ];
6
12
7
- int main (void ) {
13
+ int main () {
8
14
ios::sync_with_stdio (0 );
9
15
cin.tie (0 );
10
-
11
- }
16
+ int N, M, P;
17
+ cin >> N >> M >> P;
18
+ // 각 플레이어의 이동 제한 횟수 입력
19
+ for (int i=1 ; i<=P; i++)
20
+ cin >> step[i];
21
+ // 맵 입력
22
+ char ch;
23
+ for (int i=0 ; i<N; i++){
24
+ for (int j=0 ; j<M; j++){
25
+ cin >> ch;
26
+ if (ch == ' .' ) canExtend[i][j] = 1 ;
27
+ else if (ch == ' #' ) canExtend[i][j] = 0 ;
28
+ else {
29
+ canExtend[i][j] = 0 ;
30
+ q[ch - ' 0' ].push ({i, j, 0 }); // 각 플레이어의 초기 영토 기록
31
+ area[ch - ' 0' ] += 1 ;
32
+ }
33
+ }
34
+ }
35
+ // 게임 시작
36
+ while (1 ){
37
+ bool isExtend = 0 ;
38
+ // 1~P번 플레이어의 순차적인 영토 확장
39
+ for (int i = 1 ; i <= P; i++) {
40
+ queue<tuple<int ,int ,int >> nextq; // 다음 턴에 확장을 고려할 영토 기록
41
+ while (!q[i].empty ()) {
42
+ int curx, cury, curstep;
43
+ tie (curx, cury, curstep) = q[i].front ();
44
+ q[i].pop ();
45
+ if (curstep >= step[i]) {
46
+ nextq.push ({curx, cury, 0 });
47
+ continue ;
48
+ }
49
+ for (int dir = 0 ; dir < 4 ; dir++) {
50
+ int x = curx + dx[dir], y = cury + dy[dir];
51
+ if (x < 0 || x >= N || y < 0 || y >= M) continue ;
52
+ if (!canExtend[x][y]) continue ;
53
+ q[i].push ({x, y, curstep+1 });
54
+ canExtend[x][y] = 0 ;
55
+ area[i]++;
56
+ isExtend = 1 ;
57
+ }
58
+ }
59
+ q[i] = nextq;
60
+ }
61
+ // 아무도 영토를 확장하지 못하여 게임이 끝났는지 확인
62
+ if (!isExtend) break ;
63
+ }
64
+ // 각 플레이어의 영토 출력
65
+ for (int i=1 ; i<=P; i++)
66
+ cout << area[i] << " " ;
67
+ }
0 commit comments