# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
598324 |
2022-07-18T04:25:11 Z |
Hanksburger |
Mecho (IOI09_mecho) |
C++17 |
|
371 ms |
39284 KB |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[640005], bee;
queue<pair<int, int> > qq;
char a[640005];
bool b[640005];
int d[640005];
queue<int> q;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, p, s, e, l=-1, r=640000;
cin >> n >> p;
for (int i=0; i<n*n; i++)
{
cin >> a[i];
if (a[i]=='M')
s=i;
else if (a[i]=='D')
e=i;
else if (a[i]=='H')
bee.push_back(i);
if (a[i]!='T')
{
a[i]='G';
if (i>=n && a[i-n]=='G')
{
adj[i].push_back(i-n);
adj[i-n].push_back(i);
}
if (i%n && a[i-1]=='G')
{
adj[i].push_back(i-1);
adj[i-1].push_back(i);
}
}
}
for (int u:bee)
{
q.push(u);
b[u]=1;
}
while (!q.empty())
{
int u=q.front();
q.pop();
for (int v:adj[u])
{
if (!b[v])
{
d[v]=d[u]+1;
q.push(v);
b[v]=1;
}
}
}
while (l<r)
{
int m=(l+r+1)/2;
for (int i=0; i<n*n; i++)
b[i]=0;
qq.push({s, 0});
b[s]=1;
bool ok=0;
while (!qq.empty())
{
int u=qq.front().first, w=qq.front().second;
qq.pop();
for (int v:adj[u])
{
if (v==e)
{
ok=1;
break;
}
if (!b[v] && w+1<(d[v]-m)*p)
{
qq.push({v, w+1});
b[v]=1;
}
}
if (ok)
while (!qq.empty())
qq.pop();
}
if (ok)
l=m;
else
r=m-1;
}
cout << l;
return 0;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:65:13: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
65 | b[s]=1;
| ~~~~^~
mecho.cpp:73:17: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
73 | if (v==e)
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
15316 KB |
Output is correct |
2 |
Correct |
8 ms |
15316 KB |
Output is correct |
3 |
Correct |
8 ms |
15316 KB |
Output is correct |
4 |
Correct |
8 ms |
15316 KB |
Output is correct |
5 |
Correct |
8 ms |
15316 KB |
Output is correct |
6 |
Correct |
8 ms |
15316 KB |
Output is correct |
7 |
Correct |
325 ms |
39284 KB |
Output is correct |
8 |
Correct |
8 ms |
15316 KB |
Output is correct |
9 |
Correct |
8 ms |
15316 KB |
Output is correct |
10 |
Correct |
7 ms |
15320 KB |
Output is correct |
11 |
Correct |
8 ms |
15296 KB |
Output is correct |
12 |
Incorrect |
9 ms |
15444 KB |
Output isn't correct |
13 |
Incorrect |
8 ms |
15444 KB |
Output isn't correct |
14 |
Correct |
8 ms |
15380 KB |
Output is correct |
15 |
Correct |
8 ms |
15316 KB |
Output is correct |
16 |
Correct |
8 ms |
15316 KB |
Output is correct |
17 |
Correct |
8 ms |
15316 KB |
Output is correct |
18 |
Correct |
8 ms |
15316 KB |
Output is correct |
19 |
Correct |
8 ms |
15316 KB |
Output is correct |
20 |
Correct |
8 ms |
15316 KB |
Output is correct |
21 |
Correct |
8 ms |
15380 KB |
Output is correct |
22 |
Correct |
8 ms |
15316 KB |
Output is correct |
23 |
Correct |
8 ms |
15316 KB |
Output is correct |
24 |
Correct |
8 ms |
15316 KB |
Output is correct |
25 |
Correct |
8 ms |
15444 KB |
Output is correct |
26 |
Correct |
9 ms |
15344 KB |
Output is correct |
27 |
Correct |
9 ms |
15344 KB |
Output is correct |
28 |
Correct |
8 ms |
15444 KB |
Output is correct |
29 |
Correct |
10 ms |
15468 KB |
Output is correct |
30 |
Correct |
8 ms |
15444 KB |
Output is correct |
31 |
Correct |
8 ms |
15444 KB |
Output is correct |
32 |
Correct |
8 ms |
15444 KB |
Output is correct |
33 |
Correct |
16 ms |
18004 KB |
Output is correct |
34 |
Correct |
16 ms |
17992 KB |
Output is correct |
35 |
Correct |
43 ms |
18900 KB |
Output is correct |
36 |
Correct |
18 ms |
18764 KB |
Output is correct |
37 |
Correct |
19 ms |
18768 KB |
Output is correct |
38 |
Correct |
74 ms |
19984 KB |
Output is correct |
39 |
Correct |
21 ms |
19704 KB |
Output is correct |
40 |
Correct |
21 ms |
19692 KB |
Output is correct |
41 |
Correct |
91 ms |
21204 KB |
Output is correct |
42 |
Correct |
23 ms |
20692 KB |
Output is correct |
43 |
Correct |
24 ms |
20644 KB |
Output is correct |
44 |
Correct |
119 ms |
22592 KB |
Output is correct |
45 |
Correct |
26 ms |
21836 KB |
Output is correct |
46 |
Correct |
27 ms |
21824 KB |
Output is correct |
47 |
Correct |
160 ms |
24220 KB |
Output is correct |
48 |
Correct |
31 ms |
23060 KB |
Output is correct |
49 |
Correct |
30 ms |
23072 KB |
Output is correct |
50 |
Correct |
178 ms |
25904 KB |
Output is correct |
51 |
Correct |
33 ms |
24456 KB |
Output is correct |
52 |
Correct |
34 ms |
24396 KB |
Output is correct |
53 |
Correct |
244 ms |
27804 KB |
Output is correct |
54 |
Correct |
39 ms |
25804 KB |
Output is correct |
55 |
Correct |
39 ms |
25812 KB |
Output is correct |
56 |
Correct |
314 ms |
29720 KB |
Output is correct |
57 |
Correct |
42 ms |
27428 KB |
Output is correct |
58 |
Correct |
43 ms |
27416 KB |
Output is correct |
59 |
Correct |
338 ms |
31844 KB |
Output is correct |
60 |
Correct |
45 ms |
29060 KB |
Output is correct |
61 |
Correct |
48 ms |
29000 KB |
Output is correct |
62 |
Correct |
371 ms |
34100 KB |
Output is correct |
63 |
Correct |
206 ms |
31052 KB |
Output is correct |
64 |
Correct |
343 ms |
31172 KB |
Output is correct |
65 |
Correct |
270 ms |
31056 KB |
Output is correct |
66 |
Correct |
233 ms |
31052 KB |
Output is correct |
67 |
Correct |
222 ms |
31052 KB |
Output is correct |
68 |
Correct |
128 ms |
31152 KB |
Output is correct |
69 |
Correct |
120 ms |
31052 KB |
Output is correct |
70 |
Correct |
107 ms |
31052 KB |
Output is correct |
71 |
Correct |
108 ms |
31076 KB |
Output is correct |
72 |
Incorrect |
96 ms |
30980 KB |
Output isn't correct |
73 |
Incorrect |
193 ms |
39248 KB |
Output isn't correct |
74 |
Correct |
209 ms |
38988 KB |
Output is correct |
75 |
Correct |
236 ms |
39104 KB |
Output is correct |
76 |
Correct |
219 ms |
39144 KB |
Output is correct |
77 |
Correct |
233 ms |
39088 KB |
Output is correct |
78 |
Correct |
253 ms |
39044 KB |
Output is correct |
79 |
Correct |
179 ms |
39224 KB |
Output is correct |
80 |
Correct |
207 ms |
38960 KB |
Output is correct |
81 |
Correct |
234 ms |
39080 KB |
Output is correct |
82 |
Correct |
201 ms |
39084 KB |
Output is correct |
83 |
Correct |
292 ms |
38928 KB |
Output is correct |
84 |
Correct |
262 ms |
38976 KB |
Output is correct |
85 |
Correct |
316 ms |
39024 KB |
Output is correct |
86 |
Correct |
284 ms |
39008 KB |
Output is correct |
87 |
Correct |
299 ms |
39116 KB |
Output is correct |
88 |
Correct |
301 ms |
39036 KB |
Output is correct |
89 |
Correct |
310 ms |
38988 KB |
Output is correct |
90 |
Correct |
308 ms |
39032 KB |
Output is correct |
91 |
Correct |
304 ms |
38996 KB |
Output is correct |
92 |
Correct |
334 ms |
39036 KB |
Output is correct |