# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
258410 |
2020-08-05T22:45:59 Z |
c4ts0up |
Mecho (IOI09_mecho) |
C++17 |
|
1000 ms |
34424 KB |
/*
ID: c4ts0up
LANG: C++
TASK: Mecho
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define ff first
#define ss second
const int NMAX = 805;
const int INF = 1e9;
int n, s;
pair <int,int> home, mecho;
char grid[NMAX][NMAX];
int dist[NMAX][NMAX];
// hace el check a una coordenada
bool Check(int row, int col) {
return (0 <= row && row < n && 0 <= col && col < n);
}
// BFS para encontrar el tiempo requerido para que las abejas lleguen a un lugar
void EncontrarDistancias() {
queue <pair <int,int> > to;
set <pair <int,int> > seen;
for (int i=0; i<n; i++) for (int j=0; j<n; j++) {
if (grid[i][j] == 'H') to.push({i,j}), dist[i][j] = 0;
else dist[i][j] = INF;
}
while (!to.empty()) {
pair <int,int> curr = to.front();
to.pop();
// ya lo visitamos
if (seen.count(curr)) continue;
if (grid[curr.ff][curr.ss] == 'T' || grid[curr.ff][curr.ss] == 'D') {
seen.insert(curr);
continue;
}
// visitamos a todos los vecinos
if (!seen.count({curr.ff+1, curr.ss}) && Check(curr.ff+1, curr.ss)) to.push({curr.ff+1, curr.ss}), dist[curr.ff+1][curr.ss] = min(dist[curr.ff+1][curr.ss], dist[curr.ff][curr.ss]+1);
if (!seen.count({curr.ff-1, curr.ss}) && Check(curr.ff-1, curr.ss)) to.push({curr.ff-1, curr.ss}), dist[curr.ff-1][curr.ss] = min(dist[curr.ff-1][curr.ss], dist[curr.ff][curr.ss]+1);
if (!seen.count({curr.ff, curr.ss+1}) && Check(curr.ff, curr.ss+1)) to.push({curr.ff, curr.ss+1}), dist[curr.ff][curr.ss+1] = min(dist[curr.ff][curr.ss+1], dist[curr.ff][curr.ss]+1);
if (!seen.count({curr.ff, curr.ss-1}) && Check(curr.ff, curr.ss-1)) to.push({curr.ff, curr.ss-1}), dist[curr.ff][curr.ss-1] = min(dist[curr.ff][curr.ss-1], dist[curr.ff][curr.ss]+1);
seen.insert(curr);
}
}
bool BFS(int minutos) {
set <pair <int,int> > seen;
queue <pair <int, pair <int,int> > > to;
to.push({0, mecho});
while (!to.empty()) {
pair <int, pair <int,int> > curr = to.front();
to.pop();
// ya lo visitamos, no tenemos que volver
if (seen.count(curr.ss)) continue;
// no podemos atravesarlo
if (grid[curr.ss.ff][curr.ss.ss] == 'T') {
seen.insert(curr.ss);
continue;
}
else if (grid[curr.ss.ff][curr.ss.ss] == 'D') return true;
// ya está infestado de abejas, o sea, bloqueado
if (minutos + (curr.ff+(s-1)/s) >= dist[curr.ss.ff][curr.ss.ss]) {
seen.insert(curr.ss);
continue;
}
// visitamos a todos los vecinos
int r = curr.ss.ff;
int c = curr.ss.ss;
int pasos = curr.ff;
if (!seen.count({r+1, c}) && Check(r+1, c)) to.push({pasos, {r+1,c}});
if (!seen.count({r-1, c}) && Check(r-1, c)) to.push({pasos, {r-1,c}});
if (!seen.count({r, c+1}) && Check(r, c+1)) to.push({pasos, {r,c+1}});
if (!seen.count({r, c-1}) && Check(r, c-1)) to.push({pasos, {r,c-1}});
seen.insert({r,c});
}
return false;
}
int main() {
/*//
freopen("", "r", stdin);
freopen("", "w", stdout);
//*/
cin >> n >> s;
for (int i=0; i<n; i++) {
string aux;
cin >> aux;
for (int j=0; j<n; j++) {
grid[i][j] = aux[j];
if (grid[i][j] == 'M') mecho = {i,j};
else if (grid[i][j] == 'D') home = {i,j};
}
}
EncontrarDistancias();
int lb = 0, ub = 1e6, mid;
while (lb <= ub) {
mid = (lb+ub)/2;
if (BFS(mid)) lb = mid+1;
else ub = mid-1;
}
//cerr << "lb = " << lb << "; ub = " << ub << "; mid = " << mid << endl;
cout << ub-1 << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
7 |
Execution timed out |
1089 ms |
34168 KB |
Time limit exceeded |
8 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
768 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
692 KB |
Output isn't correct |
14 |
Incorrect |
6 ms |
768 KB |
Output isn't correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
640 KB |
Output is correct |
24 |
Correct |
2 ms |
640 KB |
Output is correct |
25 |
Correct |
2 ms |
768 KB |
Output is correct |
26 |
Correct |
3 ms |
768 KB |
Output is correct |
27 |
Correct |
2 ms |
768 KB |
Output is correct |
28 |
Correct |
3 ms |
768 KB |
Output is correct |
29 |
Correct |
3 ms |
896 KB |
Output is correct |
30 |
Correct |
3 ms |
768 KB |
Output is correct |
31 |
Correct |
3 ms |
896 KB |
Output is correct |
32 |
Correct |
4 ms |
896 KB |
Output is correct |
33 |
Correct |
62 ms |
7544 KB |
Output is correct |
34 |
Correct |
87 ms |
7672 KB |
Output is correct |
35 |
Incorrect |
793 ms |
7672 KB |
Output isn't correct |
36 |
Correct |
95 ms |
9592 KB |
Output is correct |
37 |
Correct |
97 ms |
9592 KB |
Output is correct |
38 |
Execution timed out |
1094 ms |
9776 KB |
Time limit exceeded |
39 |
Correct |
95 ms |
11768 KB |
Output is correct |
40 |
Correct |
125 ms |
11768 KB |
Output is correct |
41 |
Execution timed out |
1091 ms |
12088 KB |
Time limit exceeded |
42 |
Correct |
127 ms |
14328 KB |
Output is correct |
43 |
Correct |
154 ms |
14200 KB |
Output is correct |
44 |
Execution timed out |
1098 ms |
14456 KB |
Time limit exceeded |
45 |
Correct |
158 ms |
17016 KB |
Output is correct |
46 |
Correct |
185 ms |
17016 KB |
Output is correct |
47 |
Execution timed out |
1090 ms |
17016 KB |
Time limit exceeded |
48 |
Correct |
204 ms |
20052 KB |
Output is correct |
49 |
Correct |
215 ms |
19960 KB |
Output is correct |
50 |
Execution timed out |
1085 ms |
19960 KB |
Time limit exceeded |
51 |
Correct |
211 ms |
23160 KB |
Output is correct |
52 |
Correct |
329 ms |
23164 KB |
Output is correct |
53 |
Execution timed out |
1097 ms |
23288 KB |
Time limit exceeded |
54 |
Correct |
256 ms |
26744 KB |
Output is correct |
55 |
Correct |
306 ms |
26744 KB |
Output is correct |
56 |
Execution timed out |
1082 ms |
26884 KB |
Time limit exceeded |
57 |
Correct |
294 ms |
30456 KB |
Output is correct |
58 |
Correct |
347 ms |
30200 KB |
Output is correct |
59 |
Execution timed out |
1081 ms |
30476 KB |
Time limit exceeded |
60 |
Correct |
390 ms |
34296 KB |
Output is correct |
61 |
Correct |
395 ms |
34168 KB |
Output is correct |
62 |
Execution timed out |
1097 ms |
34172 KB |
Time limit exceeded |
63 |
Execution timed out |
1096 ms |
33912 KB |
Time limit exceeded |
64 |
Execution timed out |
1097 ms |
33912 KB |
Time limit exceeded |
65 |
Execution timed out |
1101 ms |
33912 KB |
Time limit exceeded |
66 |
Execution timed out |
1091 ms |
34040 KB |
Time limit exceeded |
67 |
Execution timed out |
1078 ms |
33856 KB |
Time limit exceeded |
68 |
Execution timed out |
1094 ms |
33912 KB |
Time limit exceeded |
69 |
Execution timed out |
1097 ms |
33912 KB |
Time limit exceeded |
70 |
Execution timed out |
1095 ms |
33872 KB |
Time limit exceeded |
71 |
Execution timed out |
1094 ms |
33972 KB |
Time limit exceeded |
72 |
Incorrect |
763 ms |
33912 KB |
Output isn't correct |
73 |
Execution timed out |
1090 ms |
34340 KB |
Time limit exceeded |
74 |
Execution timed out |
1095 ms |
34296 KB |
Time limit exceeded |
75 |
Execution timed out |
1086 ms |
34296 KB |
Time limit exceeded |
76 |
Execution timed out |
1082 ms |
34180 KB |
Time limit exceeded |
77 |
Execution timed out |
1099 ms |
34296 KB |
Time limit exceeded |
78 |
Execution timed out |
1095 ms |
34344 KB |
Time limit exceeded |
79 |
Execution timed out |
1095 ms |
34228 KB |
Time limit exceeded |
80 |
Execution timed out |
1094 ms |
34168 KB |
Time limit exceeded |
81 |
Execution timed out |
1098 ms |
34168 KB |
Time limit exceeded |
82 |
Execution timed out |
1084 ms |
34296 KB |
Time limit exceeded |
83 |
Execution timed out |
1093 ms |
34168 KB |
Time limit exceeded |
84 |
Execution timed out |
1097 ms |
34264 KB |
Time limit exceeded |
85 |
Execution timed out |
1097 ms |
34316 KB |
Time limit exceeded |
86 |
Execution timed out |
1094 ms |
34296 KB |
Time limit exceeded |
87 |
Execution timed out |
1095 ms |
34360 KB |
Time limit exceeded |
88 |
Execution timed out |
1098 ms |
34296 KB |
Time limit exceeded |
89 |
Execution timed out |
1096 ms |
34424 KB |
Time limit exceeded |
90 |
Execution timed out |
1097 ms |
34296 KB |
Time limit exceeded |
91 |
Execution timed out |
1096 ms |
34168 KB |
Time limit exceeded |
92 |
Execution timed out |
1092 ms |
34168 KB |
Time limit exceeded |