#include <bits/stdc++.h>
using namespace std;
#define pb push_back
struct tpos
{
int i, j, t;
};
bool operator < (const tpos &a, const tpos &b)
{
if (a.i == b.i) return a.j < b.j;
return a.i < b.i;
}
char mat[801][801];
int tiempo[801][801];
//int tiempo_oso[801][801];
int iini, jini, ifin, jfin;
int n, s;
vector<tpos> abejas;
bool verifica (int i, int j)
{
if (i < 0 || j < 0 || i >= n || j >= n)
return 0;
return 1;
}
int di[4] = {0, 1, 0, -1}, dj[4] = {1, 0, -1, 0};
void expande_abejas(queue<tpos> &abeja)
{
tpos t;
int ti, tj;
while (!abeja.empty())
{
t = abeja.front(); abeja.pop();
tiempo[t.i][t.j] = t.t;
for (int k = 0; k < 4; k++)
{
ti = t.i + di[k], tj = t.j + dj[k];
if (!verifica(ti, tj)) continue;
if (tiempo[ti][tj] != -1) continue;
if (mat[ti][tj] == 'T') continue;
abeja.push({ti, tj, t.t + 1});
}
}
}
bool sepuede(int t)
{
vector<vector<bool>>visi(n, vector<bool>(n, 0)); //llegue?
queue<tpos> mecho;
mecho.push({iini, jini, t});
tpos temp;
int ti, tj;
// cout << t << '\n';
int turno = 0;
visi[iini][jini] = 1;
while (!mecho.empty())
{
temp = mecho.front(); mecho.pop();
//cout << temp.i << " " << temp.j << " " <<temp.t << '\n';
/* if (t + (temp.t - t)/(s+1) > tiempo[temp.i][temp.j]) continue;
tiempo_oso[temp.i][temp.j] = temp.t;*/
int realt = (temp.t - t)/(1+s);
if (mat[temp.i][temp.j] == 'D') return 1;
for (int k = 0; k < 4; k++)
{
ti = temp.i + di[k];
tj = temp.j + dj[k];
if (!verifica(ti, tj)) continue;
if (visi[ti][tj]) continue;
if (mat[ti][tj] == 'T') continue;
if (tiempo[ti][tj] < (t + (temp.t - t + 1)/(1+s))) continue;
mecho.push({ti, tj, temp.t + 1});
visi[ti][tj] = 1;
}
}
return 0;
}
int main ()
{
/*
cin >> n >> s;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
tiempo[i][j] = -1;
cin >> mat[i][j];
if (mat[i][j] == 'M')
{
iini = i;
jini = j;
continue;
}
if (mat[i][j] == 'H')
{
abejas.pb({i, j, 0});
tiempo[i][j] = 0;
}
if (mat[i][j] == 'D')
{
ifin = i;
jfin = j;
}
}
queue<tpos> a;
for (int i = 0, l = abejas.size(); i < l; i++)
a.push(abejas[i]);
int l = 0, r = (1<<11), resp = -1;
expande_abejas(a);
while (l <= r)
{
int mit = (l+r)>>1;
if (sepuede(mit))
{
resp = mit;
l = mit+1;
continue;
}
r = mit-1;
}*/
cout << -1;
/* for (int i = 0; i < n; i++, cout << '\n')
for (int j = 0; j < n; j++)
cout << tiempo[i][j] << " ";
cout << '\n';
sepuede(2);
for (int i = 0; i < n; i++, cout << '\n')
for (int j = 0; j < n; j++)
cout << tiempo_oso[i][j] << " ";
//cout << resp;
//sepuede(1);
*/
return 0;
}
Compilation message
mecho.cpp: In function 'bool sepuede(int)':
mecho.cpp:62:13: warning: unused variable 'realt' [-Wunused-variable]
62 | int realt = (temp.t - t)/(1+s);
| ^~~~~
mecho.cpp:54:9: warning: unused variable 'turno' [-Wunused-variable]
54 | int turno = 0;
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
392 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 |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
20 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
21 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
22 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
23 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
24 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
25 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
26 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
27 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
28 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
29 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
30 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
31 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
32 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
33 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
34 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
35 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
36 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
37 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
38 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
39 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
40 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
41 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
42 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
43 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
44 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
45 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
46 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
47 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
48 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
49 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
50 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
51 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
52 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
53 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
54 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
55 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
56 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
57 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
58 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
59 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
60 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
61 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
62 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
63 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
64 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
65 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
66 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
67 |
Correct |
0 ms |
348 KB |
Output is correct |
68 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
69 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
70 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
71 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
72 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
73 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
74 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
75 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
76 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
77 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
80 |
Incorrect |
0 ms |
428 KB |
Output isn't correct |
81 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
82 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
83 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
84 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
85 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
86 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
87 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
88 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
89 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
90 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
91 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
92 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |