-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSW expert-줄기세포 배양.cpp.txt
106 lines (98 loc) · 1.95 KB
/
SW expert-줄기세포 배양.cpp.txt
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
#include<map>
#include<queue>
#include<utility>
#include<functional>
#include<tuple>
using namespace std;
int dx[4] = { -1,1,0,0 };
int dy[4] = { 0,0,-1,1 };
int arr[700][700];
int depth[700][700];
int die[700][700];
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int Testcase, countT;
cin >> Testcase;
countT = 1;
while (Testcase!=0)
{
int N, M, K;
int ret = 0;
priority_queue < tuple<int,int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq;
cin >> N >> M >> K;
for (int i = 0; i < 700; i++)
{
for (int j = 0; j < 700; j++)
{
arr[i][j] = 0;
depth[i][j] = 0;
die[i][j] = -1;
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
int num;
cin >> num;
arr[i + 300][j + 300] = num;
if (num != 0)
{
pq.push(make_tuple(1,11-num, (i+300) * 700 + j+300));
depth[i + 300][j + 300] = 1;
ret++;
}
}
}
while (!pq.empty())
{
int x = get<2>(pq.top()) / 700;
int y = get<2>(pq.top()) % 700;
int dep = get<0>(pq.top());
pq.pop();
if (dep >= K + 1)
{
for (int i = 0; i < 700; i++)
{
for (int j = 0; j < 700; j++)
{
if (die[i][j] != -1)
{
if (K + 1 - die[i][j] >= arr[i][j])
ret--;
}
}
}
cout << "#" << countT++ << " " << ret << "\n";
break;
}
if (depth[x][y] == arr[x][y] + 1)
{
for (int i = 0; i < 4; i++)
{
int Gx = x + dx[i];
int Gy = y + dy[i];
if (arr[Gx][Gy] == 0)
{
arr[Gx][Gy] = arr[x][y];
depth[Gx][Gy] = arr[x][y] + 1;
pq.push(make_tuple(dep + arr[x][y] + 1,11-arr[x][y], Gx * 700 + Gy));
ret++;
}
}
die[x][y] = dep;
}
else
{
dep += (arr[x][y] + 1 - depth[x][y]);
depth[x][y] = arr[x][y] + 1;
pq.push(make_tuple(dep, 11 - arr[x][y], x * 700 + y));
}
}
Testcase--;
}
return 0;
}