1
- // Authored by : BaaaaaaaaaaarkingDog
1
+ // Authored by : diyamea
2
2
// Co-authored by : -
3
- // http://boj.kr/****************
3
+ // http://boj.kr/260be750bc42457787ca285051b931c2
4
+
4
5
#include < bits/stdc++.h>
5
6
using namespace std ;
6
7
7
- int main (void ){
8
- ios::sync_with_stdio (0 );
9
- cin.tie (0 );
10
-
11
- }
8
+ // clockwise
9
+ int dx[4 ] = {0 ,1 ,0 ,-1 };
10
+ int dy[4 ] = {1 ,0 ,-1 ,0 };
11
+
12
+ // counter-clockwise
13
+ int cdx[4 ] = {0 ,-1 ,0 ,1 };
14
+ int cdy[4 ] = {1 ,0 ,-1 ,0 };
15
+
16
+ int r,c,t;
17
+ array<array<int , 55 >, 55 > room;
18
+ array<array<int , 55 >, 55 > dummy;
19
+ array<array<int , 55 >, 55 > dummy2;
20
+ int machine_bottom;
21
+
22
+ void dust_spread () {
23
+ for (int i{}; i<r; ++i) {
24
+ for (int j{}; j<c; ++j) {
25
+ if (room[i][j] <= 0 ) continue ;
26
+ dummy2[i][j] = room[i][j];
27
+ for (int dir{}; dir<4 ; ++dir) {
28
+ auto x = i+dx[dir];
29
+ auto y = j+dy[dir];
30
+ if (x < 0 || y < 0 || x >= r || y >= c) continue ;
31
+ if (room[x][y] == -1 ) continue ;
32
+ dummy[x][y] += room[i][j]/5 ;
33
+ dummy2[i][j] -= room[i][j]/5 ;
34
+ }
35
+ }
36
+ }
37
+ for (int i{}; i<r; ++i) {
38
+ for (int j{}; j<c; ++j) {
39
+ if (room[i][j] == -1 ) continue ;
40
+ room[i][j] = dummy[i][j]+dummy2[i][j];
41
+ }
42
+ }
43
+ dummy = {};
44
+ dummy2 = {};
45
+ }
46
+
47
+ void clockwise_wind (int i, int j, int dir, int prev_dust) {
48
+ if (room[i][j] == -1 ) return ;
49
+
50
+ auto move_dust = room[i][j];
51
+ room[i][j] = prev_dust;
52
+ auto x = i+dx[dir];
53
+ auto y = j+dy[dir];
54
+ if (x < 0 || y < 0 || x >= r || y >= c) {
55
+ dir++;
56
+ x = i+dx[dir];
57
+ y = j+dy[dir];
58
+ clockwise_wind (x, y, dir, move_dust);
59
+ }
60
+ else
61
+ clockwise_wind (x, y, dir, move_dust);
62
+ }
63
+
64
+ void counter_clockwise_wind (int i, int j, int dir, int prev_dust) {
65
+ if (room[i][j] == -1 ) return ;
66
+
67
+ auto move_dust = room[i][j];
68
+ room[i][j] = prev_dust;
69
+ auto x = i+cdx[dir];
70
+ auto y = j+cdy[dir];
71
+ if (x < 0 || y < 0 || x >= r || y >= c) {
72
+ dir++;
73
+ x = i+cdx[dir];
74
+ y = j+cdy[dir];
75
+ counter_clockwise_wind (x, y, dir, move_dust);
76
+ }
77
+ else
78
+ counter_clockwise_wind (x, y, dir, move_dust);
79
+ }
80
+
81
+ void air_cleaner () {
82
+ auto x2 = machine_bottom;
83
+ auto x1 = x2-1 ;
84
+
85
+ counter_clockwise_wind (x1, 1 , 0 , 0 );
86
+ clockwise_wind (x2, 1 , 0 , 0 );
87
+ }
88
+
89
+ int dust_sum () {
90
+ int sum = 0 ;
91
+ for (int i{}; i<r; ++i) {
92
+ for (int j{}; j<c; ++j) {
93
+ if (room[i][j] == -1 ) continue ;
94
+ sum += room[i][j];
95
+ }
96
+ }
97
+ return sum;
98
+ }
99
+
100
+ int main () {
101
+ ios::sync_with_stdio (false );
102
+ cin.tie (NULL );
103
+
104
+ cin >> r >> c >> t;
105
+
106
+ for (int i{}; i<r; ++i) {
107
+ for (int j{}; j<c; ++j) {
108
+ cin >> room[i][j];
109
+ if (room[i][j] == -1 )
110
+ machine_bottom = i;
111
+ }
112
+ }
113
+ while (t--) {
114
+ dust_spread ();
115
+ air_cleaner ();
116
+ }
117
+
118
+ cout << dust_sum ();
119
+ }
0 commit comments