# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
404240 |
2021-05-14T01:58:06 Z |
AlexRex0 |
Mecho (IOI09_mecho) |
C++14 |
|
337 ms |
6484 KB |
#include <bits/stdc++.h>
using namespace std;
int n, s, xini, yini, xfin, yfin;
bool visitado[802][802];
char a[802][802];
int abejas[802][802];
struct dato{
int x;
int y;
int tiempo;
};
int mov[4][2] = {{1,0}, {0,1}, {-1, 0}, {0, - 1}};
queue<dato> cola;
dato aux, nuevo;
void buscaA(){
while(!cola.empty()){
aux = cola.front();
cola.pop();
if(!visitado[aux.x][aux.y]){
if(aux.x > n || aux.x < 1 || aux.y > n || aux.y < 1 || a[aux.x][aux.y] == 'T' || a[aux.x][aux.y] == 'D'){
}else{
visitado[aux.x][aux.y] = true;
abejas[aux.x][aux.y] = aux.tiempo;
for(int i = 0; i < 4; ++i){
nuevo.tiempo = aux.tiempo + 1;
nuevo.x = aux.x + mov[i][0];
nuevo.y = aux.y + mov[i][1];
cola.push(nuevo);
}
}
}
}
}
struct oso{
int x;
int y;
int minutos;
int cont;
};
oso inicial, frenteO, nuevoO;
queue<oso> colaO;
bool visitadoOso[802][802];
bool valido(int t){
inicial.minutos = t;
inicial.x = xini;
inicial.y = yini;
inicial.cont = 0;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
visitadoOso[i][j] = false;
}
}
colaO.push(inicial);
while(!colaO.empty()){
frenteO = colaO.front();
colaO.pop();
if(!visitadoOso[frenteO.x][frenteO.y]){
if(frenteO.x > n || frenteO.x < 1 || frenteO.y > n || frenteO.y < 1 || a[frenteO.x][frenteO.y] == 'T' || a[frenteO.x][frenteO.y] == 'H'){
}else{
if(frenteO.minutos < abejas[frenteO.x][frenteO.y] || (frenteO.x == xfin && frenteO.y == yfin)){
visitadoOso[frenteO.x][frenteO.y] = true;
for(int i = 0; i < 4; ++i){
nuevoO.cont = frenteO.cont + 1;
nuevoO.minutos = frenteO.minutos;
nuevoO.x = frenteO.x + mov[i][0];
nuevoO.y = frenteO.y + mov[i][1];
if(nuevoO.cont >= s){
nuevoO.cont = 0;
nuevoO.minutos++;
}
colaO.push(nuevoO);
}
}
}
}
}
if(visitadoOso[xfin][yfin]){
return true;
}
return false;
}
int bs(){
int inf = 0; int sup = n * n, medio, res = -1;
while(inf <= sup){
medio = (inf + sup) / 2;
if(valido(medio)){
res = medio;
inf = medio + 1;
}else{
sup = medio - 1;
}
}
return res;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> s;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
cin >> a[i][j];
if(a[i][j] == 'H'){
aux.x = i;
aux.y = j;
aux.tiempo = 0;
cola.push(aux);
}
if(a[i][j] == 'M'){
xini = i;
yini = j;
}
if(a[i][j] == 'D'){
xfin = i;
yfin = j;
}
}
}
buscaA();
cout << bs();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
178 ms |
5488 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
2 ms |
592 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
592 KB |
Output is correct |
24 |
Correct |
1 ms |
588 KB |
Output is correct |
25 |
Correct |
1 ms |
592 KB |
Output is correct |
26 |
Correct |
1 ms |
588 KB |
Output is correct |
27 |
Correct |
1 ms |
724 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
1 ms |
716 KB |
Output is correct |
30 |
Correct |
1 ms |
716 KB |
Output is correct |
31 |
Correct |
1 ms |
716 KB |
Output is correct |
32 |
Correct |
2 ms |
720 KB |
Output is correct |
33 |
Correct |
10 ms |
2380 KB |
Output is correct |
34 |
Correct |
11 ms |
2388 KB |
Output is correct |
35 |
Correct |
49 ms |
2380 KB |
Output is correct |
36 |
Correct |
12 ms |
2636 KB |
Output is correct |
37 |
Correct |
14 ms |
2628 KB |
Output is correct |
38 |
Correct |
62 ms |
2700 KB |
Output is correct |
39 |
Correct |
15 ms |
2892 KB |
Output is correct |
40 |
Correct |
18 ms |
2948 KB |
Output is correct |
41 |
Correct |
87 ms |
2892 KB |
Output is correct |
42 |
Correct |
18 ms |
3124 KB |
Output is correct |
43 |
Correct |
21 ms |
3160 KB |
Output is correct |
44 |
Correct |
105 ms |
3148 KB |
Output is correct |
45 |
Correct |
22 ms |
3484 KB |
Output is correct |
46 |
Correct |
25 ms |
3440 KB |
Output is correct |
47 |
Correct |
118 ms |
3468 KB |
Output is correct |
48 |
Correct |
25 ms |
3660 KB |
Output is correct |
49 |
Correct |
30 ms |
3680 KB |
Output is correct |
50 |
Correct |
143 ms |
3720 KB |
Output is correct |
51 |
Correct |
29 ms |
3908 KB |
Output is correct |
52 |
Correct |
34 ms |
4036 KB |
Output is correct |
53 |
Correct |
188 ms |
4096 KB |
Output is correct |
54 |
Correct |
34 ms |
4420 KB |
Output is correct |
55 |
Correct |
41 ms |
4292 KB |
Output is correct |
56 |
Correct |
216 ms |
4280 KB |
Output is correct |
57 |
Correct |
38 ms |
4516 KB |
Output is correct |
58 |
Correct |
45 ms |
4548 KB |
Output is correct |
59 |
Correct |
240 ms |
4664 KB |
Output is correct |
60 |
Correct |
44 ms |
4768 KB |
Output is correct |
61 |
Correct |
51 ms |
4804 KB |
Output is correct |
62 |
Correct |
274 ms |
4904 KB |
Output is correct |
63 |
Correct |
179 ms |
4800 KB |
Output is correct |
64 |
Correct |
337 ms |
4932 KB |
Output is correct |
65 |
Correct |
254 ms |
4848 KB |
Output is correct |
66 |
Correct |
206 ms |
4868 KB |
Output is correct |
67 |
Correct |
198 ms |
4804 KB |
Output is correct |
68 |
Correct |
80 ms |
4896 KB |
Output is correct |
69 |
Correct |
79 ms |
4932 KB |
Output is correct |
70 |
Correct |
60 ms |
4916 KB |
Output is correct |
71 |
Correct |
73 ms |
5136 KB |
Output is correct |
72 |
Correct |
50 ms |
4996 KB |
Output is correct |
73 |
Correct |
69 ms |
6388 KB |
Output is correct |
74 |
Correct |
118 ms |
6448 KB |
Output is correct |
75 |
Correct |
149 ms |
6484 KB |
Output is correct |
76 |
Correct |
139 ms |
6484 KB |
Output is correct |
77 |
Correct |
133 ms |
6372 KB |
Output is correct |
78 |
Correct |
159 ms |
6288 KB |
Output is correct |
79 |
Correct |
102 ms |
6276 KB |
Output is correct |
80 |
Correct |
128 ms |
6320 KB |
Output is correct |
81 |
Correct |
143 ms |
6244 KB |
Output is correct |
82 |
Correct |
131 ms |
6268 KB |
Output is correct |
83 |
Correct |
161 ms |
6040 KB |
Output is correct |
84 |
Correct |
146 ms |
6024 KB |
Output is correct |
85 |
Correct |
161 ms |
5952 KB |
Output is correct |
86 |
Correct |
155 ms |
5956 KB |
Output is correct |
87 |
Correct |
159 ms |
6064 KB |
Output is correct |
88 |
Correct |
166 ms |
5772 KB |
Output is correct |
89 |
Correct |
170 ms |
5768 KB |
Output is correct |
90 |
Correct |
174 ms |
5700 KB |
Output is correct |
91 |
Correct |
178 ms |
5804 KB |
Output is correct |
92 |
Correct |
185 ms |
5672 KB |
Output is correct |