# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1012606 |
2024-07-02T11:33:35 Z |
toast12 |
Mecho (IOI09_mecho) |
C++14 |
|
1000 ms |
7672 KB |
#include <bits/stdc++.h>
using namespace std;
int n, s;
vector<vector<char>> grid;
vector<vector<int>> dist;
int eating_time;
bool reachable(int mecho, int bee) {
return (((mecho/s)+eating_time < bee) || (bee == -1)) && (mecho != -1);
}
void bfs(queue<pair<int, int>> &q, vector<vector<int>> &d) {
while (!q.empty()) {
int x = q.front().first;
int y = q.front().second;
q.pop();
if (x < 1 || y < 1 || x > n || y > n)
continue;
if (d[x+1][y] == -1 && grid[x+1][y] != 'X' && reachable(d[x][y]+1, dist[x+1][y])) {
q.push({x+1, y});
d[x+1][y] = d[x][y]+1;
}
if (d[x-1][y] == -1 && grid[x-1][y] != 'X' && reachable(d[x][y]+1, dist[x-1][y])) {
q.push({x-1, y});
d[x-1][y] = d[x][y]+1;
}
if (d[x][y+1] == -1 && grid[x][y+1] != 'X' && reachable(d[x][y]+1, dist[x][y+1])) {
q.push({x, y+1});
d[x][y+1] = d[x][y]+1;
}
if (d[x][y-1] == -1 && grid[x][y-1] != 'X' && reachable(d[x][y]+1, dist[x][y-1])) {
q.push({x, y-1});
d[x][y-1] = d[x][y]+1;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> s;
grid.resize(n+2, vector<char>(n+2, '.'));
pair<int, int> start, end;
queue<pair<int, int>> q;
dist.resize(n+2, vector<int>(n+2, -1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> grid[i][j];
if (grid[i][j] == 'G')
grid[i][j] = '.';
else if (grid[i][j] == 'T')
grid[i][j] = 'X';
else if (grid[i][j] == 'M')
start = {i, j};
else if (grid[i][j] == 'D')
end = {i, j};
else {
q.push({i, j});
dist[i][j] = 0;
}
}
}
// distance for bees
while (!q.empty()) {
int x = q.front().first;
int y = q.front().second;
q.pop();
if (x < 1 || y < 1 || x > n || y > n)
continue;
if (dist[x+1][y] == -1 && grid[x+1][y] != 'X') {
q.push({x+1, y});
dist[x+1][y] = dist[x][y]+1;
}
if (dist[x-1][y] == -1 && grid[x-1][y] != 'X') {
q.push({x-1, y});
dist[x-1][y] = dist[x][y]+1;
}
if (dist[x][y+1] == -1 && grid[x][y+1] != 'X') {
q.push({x, y+1});
dist[x][y+1] = dist[x][y]+1;
}
if (dist[x][y-1] == -1 && grid[x][y-1] != 'X') {
q.push({x, y-1});
dist[x][y-1] = dist[x][y]+1;
}
}
int ans = -1;
for (int i = n*n; i >= 0; i--) {
vector<vector<int>> d(n+2, vector<int>(n+2, -1));
d[start.first][start.second] = 0;
eating_time = i;
q.push(start);
if (!reachable(d[start.first][start.second], dist[start.first][start.second]))
q.pop();
bfs(q, d);
if (reachable(d[end.first][end.second], dist[end.first][end.second])) {
ans = i;
break;
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Execution timed out |
1097 ms |
7132 KB |
Time limit exceeded |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
6 ms |
344 KB |
Output isn't correct |
13 |
Correct |
4 ms |
348 KB |
Output is correct |
14 |
Correct |
7 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
3 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
504 KB |
Output is correct |
26 |
Correct |
6 ms |
604 KB |
Output is correct |
27 |
Correct |
5 ms |
348 KB |
Output is correct |
28 |
Correct |
7 ms |
508 KB |
Output is correct |
29 |
Correct |
7 ms |
520 KB |
Output is correct |
30 |
Correct |
8 ms |
516 KB |
Output is correct |
31 |
Correct |
7 ms |
344 KB |
Output is correct |
32 |
Correct |
10 ms |
348 KB |
Output is correct |
33 |
Execution timed out |
1044 ms |
1708 KB |
Time limit exceeded |
34 |
Execution timed out |
1075 ms |
1716 KB |
Time limit exceeded |
35 |
Execution timed out |
1062 ms |
3468 KB |
Time limit exceeded |
36 |
Execution timed out |
1074 ms |
2380 KB |
Time limit exceeded |
37 |
Execution timed out |
1076 ms |
3524 KB |
Time limit exceeded |
38 |
Execution timed out |
1044 ms |
2084 KB |
Time limit exceeded |
39 |
Execution timed out |
1029 ms |
2532 KB |
Time limit exceeded |
40 |
Execution timed out |
1063 ms |
3512 KB |
Time limit exceeded |
41 |
Execution timed out |
1030 ms |
3492 KB |
Time limit exceeded |
42 |
Execution timed out |
1034 ms |
3984 KB |
Time limit exceeded |
43 |
Execution timed out |
1058 ms |
3304 KB |
Time limit exceeded |
44 |
Execution timed out |
1098 ms |
3084 KB |
Time limit exceeded |
45 |
Execution timed out |
1072 ms |
3500 KB |
Time limit exceeded |
46 |
Execution timed out |
1067 ms |
3576 KB |
Time limit exceeded |
47 |
Execution timed out |
1014 ms |
4184 KB |
Time limit exceeded |
48 |
Execution timed out |
1056 ms |
4528 KB |
Time limit exceeded |
49 |
Execution timed out |
1071 ms |
4052 KB |
Time limit exceeded |
50 |
Execution timed out |
1048 ms |
4576 KB |
Time limit exceeded |
51 |
Execution timed out |
1047 ms |
5140 KB |
Time limit exceeded |
52 |
Execution timed out |
1026 ms |
4908 KB |
Time limit exceeded |
53 |
Execution timed out |
1064 ms |
5252 KB |
Time limit exceeded |
54 |
Execution timed out |
1063 ms |
5828 KB |
Time limit exceeded |
55 |
Execution timed out |
1051 ms |
5768 KB |
Time limit exceeded |
56 |
Execution timed out |
1063 ms |
5776 KB |
Time limit exceeded |
57 |
Execution timed out |
1071 ms |
6524 KB |
Time limit exceeded |
58 |
Execution timed out |
1057 ms |
6348 KB |
Time limit exceeded |
59 |
Execution timed out |
1059 ms |
6324 KB |
Time limit exceeded |
60 |
Execution timed out |
1066 ms |
7144 KB |
Time limit exceeded |
61 |
Execution timed out |
1029 ms |
7184 KB |
Time limit exceeded |
62 |
Execution timed out |
1049 ms |
7132 KB |
Time limit exceeded |
63 |
Execution timed out |
1048 ms |
7392 KB |
Time limit exceeded |
64 |
Execution timed out |
1065 ms |
7088 KB |
Time limit exceeded |
65 |
Execution timed out |
1063 ms |
7132 KB |
Time limit exceeded |
66 |
Execution timed out |
1010 ms |
7556 KB |
Time limit exceeded |
67 |
Execution timed out |
1062 ms |
7120 KB |
Time limit exceeded |
68 |
Execution timed out |
1056 ms |
7248 KB |
Time limit exceeded |
69 |
Execution timed out |
1008 ms |
7148 KB |
Time limit exceeded |
70 |
Execution timed out |
1043 ms |
7236 KB |
Time limit exceeded |
71 |
Execution timed out |
1034 ms |
7152 KB |
Time limit exceeded |
72 |
Execution timed out |
1040 ms |
7368 KB |
Time limit exceeded |
73 |
Execution timed out |
1075 ms |
7132 KB |
Time limit exceeded |
74 |
Execution timed out |
1063 ms |
7260 KB |
Time limit exceeded |
75 |
Execution timed out |
1054 ms |
7472 KB |
Time limit exceeded |
76 |
Execution timed out |
1056 ms |
7208 KB |
Time limit exceeded |
77 |
Execution timed out |
1055 ms |
7144 KB |
Time limit exceeded |
78 |
Execution timed out |
1061 ms |
7296 KB |
Time limit exceeded |
79 |
Execution timed out |
1008 ms |
7536 KB |
Time limit exceeded |
80 |
Execution timed out |
1077 ms |
7228 KB |
Time limit exceeded |
81 |
Execution timed out |
1054 ms |
7120 KB |
Time limit exceeded |
82 |
Execution timed out |
1063 ms |
7156 KB |
Time limit exceeded |
83 |
Execution timed out |
1049 ms |
7196 KB |
Time limit exceeded |
84 |
Execution timed out |
1074 ms |
7144 KB |
Time limit exceeded |
85 |
Execution timed out |
1046 ms |
7672 KB |
Time limit exceeded |
86 |
Execution timed out |
1067 ms |
7184 KB |
Time limit exceeded |
87 |
Execution timed out |
1043 ms |
7224 KB |
Time limit exceeded |
88 |
Execution timed out |
1039 ms |
7228 KB |
Time limit exceeded |
89 |
Execution timed out |
1044 ms |
7468 KB |
Time limit exceeded |
90 |
Execution timed out |
1068 ms |
7464 KB |
Time limit exceeded |
91 |
Execution timed out |
1053 ms |
7168 KB |
Time limit exceeded |
92 |
Execution timed out |
1082 ms |
7192 KB |
Time limit exceeded |