#include<bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int dx[] = {1, 0, 0, -1};
const int dy[] = {0, 1, -1, 0};
const int MAXN = 8e2 + 10;
const int inf = 1e9 + 7;
int n, s;
int xe, ye;
int grid[MAXN][MAXN];
int loangbee[MAXN][MAXN];
int loangpl[MAXN][MAXN];
bool exceed(int x, int y) {
return (x > n || x < 1 || y > n || y < 1);
}
void bfsbee() {
queue<pair<int, int>> q;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (grid[i][j] == 4) {
q.push({i, j});
loangbee[i][j] = 0;
}
}
}
while (!q.empty()) {
pii temp = q.front();
q.pop();
int x = temp.fi;
int y = temp.se;
for (int i = 0; i < 4; i++) {
int u = x + dx[i];
int v = y + dy[i];
if (!exceed(u, v)) {
if (loangbee[u][v] == inf && grid[u][v] == 1) {
loangbee[u][v] = loangbee[x][y] + 1;
q.push({u, v});
}
}
}
}
}
int bfspl(int original_value) {
queue<pair<int, int>> q;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (grid[i][j] == 2) {
q.push({i, j});
loangpl[i][j] = 0;
}
else {
loangpl[i][j] = inf;
}
}
}
while (!q.empty()) {
pii temp = q.front();
q.pop();
int x = temp.fi;
int y = temp.se;
for (int i = 0; i < 4; i++) {
int u = x + dx[i];
int v = y + dy[i];
if (!exceed(u, v)) {
if (loangpl[u][v] == inf && grid[u][v] == 1) {
if ((loangpl[x][y] + 1) / s < loangbee[u][v] - original_value) {
q.push({u, v});
loangpl[u][v] = loangpl[x][y] + 1;
};
}
}
}
}
for (int i = 0; i < 4; i++) {
int u = xe + dx[i];
int v = xe + dy[i];
if (loangpl[u][v] != inf) return 1;
}
return 0;
}
int main() {
cin >> n >> s;
for (int i = 1; i <= n; i++) {
string str;
cin >> str;
for (int j = 1; j <= n; j++) {
char c = str[j-1];
loangpl[i][j] = inf;
loangbee[i][j] = inf;
if (c == 'T') {
grid[i][j] = 0;
}
if (c == 'G') grid[i][j] = 1;
if (c == 'M') grid[i][j] = 2;
if (c == 'D') {
grid[i][j] = 1;
xe = i;
ye = j;
}
if (c == 'H') grid[i][j] = 4;
}
}
bfsbee();
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= n; j++) {
// cout << loangbee[i][j] << " ";
// }
// cout << endl;
// }
// cout << "map nguoi" << endl;
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= n; j++) {
// cout << loangpl[i][j] << " ";
// }
// cout << endl;
//
int l = 0, r = n * n;
while (l <= r) {
int mid = (l + r) / 2;
if (bfspl(mid) == 1) {
l = mid + 1;
}
else r = mid - 1;
}
cout << l - 1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
79 ms |
7972 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Incorrect |
0 ms |
860 KB |
Output isn't correct |
24 |
Correct |
1 ms |
860 KB |
Output is correct |
25 |
Incorrect |
0 ms |
860 KB |
Output isn't correct |
26 |
Correct |
1 ms |
860 KB |
Output is correct |
27 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
28 |
Correct |
1 ms |
860 KB |
Output is correct |
29 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
30 |
Correct |
1 ms |
1116 KB |
Output is correct |
31 |
Incorrect |
1 ms |
1168 KB |
Output isn't correct |
32 |
Correct |
1 ms |
1116 KB |
Output is correct |
33 |
Incorrect |
6 ms |
3672 KB |
Output isn't correct |
34 |
Correct |
7 ms |
3684 KB |
Output is correct |
35 |
Incorrect |
6 ms |
3672 KB |
Output isn't correct |
36 |
Incorrect |
7 ms |
4188 KB |
Output isn't correct |
37 |
Correct |
8 ms |
4188 KB |
Output is correct |
38 |
Incorrect |
8 ms |
4268 KB |
Output isn't correct |
39 |
Incorrect |
9 ms |
4700 KB |
Output isn't correct |
40 |
Correct |
10 ms |
4700 KB |
Output is correct |
41 |
Incorrect |
10 ms |
4700 KB |
Output isn't correct |
42 |
Incorrect |
10 ms |
5212 KB |
Output isn't correct |
43 |
Correct |
13 ms |
5208 KB |
Output is correct |
44 |
Incorrect |
12 ms |
5216 KB |
Output isn't correct |
45 |
Incorrect |
17 ms |
5468 KB |
Output isn't correct |
46 |
Correct |
14 ms |
5468 KB |
Output is correct |
47 |
Incorrect |
13 ms |
5468 KB |
Output isn't correct |
48 |
Incorrect |
16 ms |
5980 KB |
Output isn't correct |
49 |
Correct |
22 ms |
6160 KB |
Output is correct |
50 |
Incorrect |
18 ms |
5980 KB |
Output isn't correct |
51 |
Incorrect |
17 ms |
6492 KB |
Output isn't correct |
52 |
Correct |
22 ms |
6636 KB |
Output is correct |
53 |
Incorrect |
18 ms |
6492 KB |
Output isn't correct |
54 |
Incorrect |
20 ms |
7004 KB |
Output isn't correct |
55 |
Correct |
34 ms |
7004 KB |
Output is correct |
56 |
Incorrect |
23 ms |
6872 KB |
Output isn't correct |
57 |
Incorrect |
23 ms |
7516 KB |
Output isn't correct |
58 |
Correct |
26 ms |
7512 KB |
Output is correct |
59 |
Incorrect |
23 ms |
7596 KB |
Output isn't correct |
60 |
Incorrect |
27 ms |
8028 KB |
Output isn't correct |
61 |
Correct |
28 ms |
8028 KB |
Output is correct |
62 |
Incorrect |
32 ms |
8028 KB |
Output isn't correct |
63 |
Incorrect |
34 ms |
8028 KB |
Output isn't correct |
64 |
Incorrect |
37 ms |
8028 KB |
Output isn't correct |
65 |
Incorrect |
34 ms |
8028 KB |
Output isn't correct |
66 |
Incorrect |
43 ms |
8004 KB |
Output isn't correct |
67 |
Incorrect |
35 ms |
8024 KB |
Output isn't correct |
68 |
Incorrect |
47 ms |
8024 KB |
Output isn't correct |
69 |
Incorrect |
37 ms |
8028 KB |
Output isn't correct |
70 |
Incorrect |
36 ms |
8024 KB |
Output isn't correct |
71 |
Incorrect |
37 ms |
8064 KB |
Output isn't correct |
72 |
Incorrect |
39 ms |
8028 KB |
Output isn't correct |
73 |
Incorrect |
31 ms |
8284 KB |
Output isn't correct |
74 |
Incorrect |
31 ms |
8284 KB |
Output isn't correct |
75 |
Incorrect |
35 ms |
8284 KB |
Output isn't correct |
76 |
Incorrect |
37 ms |
8280 KB |
Output isn't correct |
77 |
Incorrect |
32 ms |
8284 KB |
Output isn't correct |
78 |
Incorrect |
56 ms |
8280 KB |
Output isn't correct |
79 |
Incorrect |
54 ms |
8284 KB |
Output isn't correct |
80 |
Incorrect |
53 ms |
8280 KB |
Output isn't correct |
81 |
Incorrect |
53 ms |
8280 KB |
Output isn't correct |
82 |
Incorrect |
49 ms |
8284 KB |
Output isn't correct |
83 |
Incorrect |
60 ms |
8276 KB |
Output isn't correct |
84 |
Incorrect |
53 ms |
8140 KB |
Output isn't correct |
85 |
Incorrect |
55 ms |
8248 KB |
Output isn't correct |
86 |
Incorrect |
55 ms |
8028 KB |
Output isn't correct |
87 |
Incorrect |
58 ms |
8028 KB |
Output isn't correct |
88 |
Incorrect |
62 ms |
8028 KB |
Output isn't correct |
89 |
Incorrect |
65 ms |
8200 KB |
Output isn't correct |
90 |
Incorrect |
64 ms |
8200 KB |
Output isn't correct |
91 |
Incorrect |
66 ms |
8024 KB |
Output isn't correct |
92 |
Incorrect |
66 ms |
8028 KB |
Output isn't correct |