8000 Update 16235.cpp · JeeeunOh/basic-algo-lecture@766bed7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 766bed7

Browse files
author
SciEm
committed
Update 16235.cpp
1 parent 31e0565 commit 766bed7

File tree

1 file changed

+61
-5
lines changed

1 file changed

+61
-5
lines changed

0x0D/solutions/16235.cpp

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,67 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : SciEm
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/4a2716a7e1464152812bb968b64b0b54
44
#include <bits/stdc++.h>
55
using namespace std;
66

7-
int main(void){
7+
int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
8+
int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
9+
int field[12][12];
10+
int S2D2[12][12];
11+
vector<int> tree[12][12]; // 나무의 나이를 벡터에 저장
12+
int n, m, k;
13+
14+
void run1(int x, int y) {
15+
auto& v = tree[x][y];
16+
//
17+
auto rit = v.rbegin();
18+
for (; rit != v.rend() && *rit <= field[x][y]; rit++)
19+
field[x][y] -= (*rit)++;
20+
auto vend = rit.base();
21+
// 여름
22+
for (; rit != v.rend(); rit++)
23+
field[x][y] += *rit / 2;
24+
v.erase(v.begin(), vend);
25+
}
26+
27+
void run2(int x, int y) {
28+
// 가을
29+
for (auto age : tree[x][y])
30+
if (!(age % 5))
31+
for (int dir = 0; dir < 8; dir++)
32+
tree[x + dx[dir]][y + dy[dir]].push_back(1);
33+
// 겨울
34+
field[x][y] += S2D2[x][y];
35+
}
36+
37+
int main() {
838
ios::sync_with_stdio(0);
939
cin.tie(0);
10-
11-
}
40+
41+
cin >> n >> m >> k;
42+
for (int i = 1; i <= n; i++)
43+
for (int j = 1; j <= n; j++) {
44+
field[i][j] = 5;
45+
cin >> S2D2[i][j];
46+
}
47+
while (m--) {
48+
int x, y, z;
49+
cin >> x >> y >> z;
50+
tree[x][y].push_back(z);
51+
}
52+
53+
while (k--) {
54+
for (int i = 1; i <= n; i++)
55+
for (int j = 1; j <= n; j++)
56+
run1(i, j);
57+
for (int i = 1; i <= n; i++)
58+
for (int j = 1; j <= n; j++)
59+
run2(i, j);
60+
}
61+
62+
int ans = 0;
63+
for (int i = 1; i <= n; i++)
64+
for (int j = 1; j <= n; j++)
65+
ans += tree[i][j].size();
66+
cout << ans;
67+
}

0 commit comments

Comments
 (0)
0