# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
408684 |
2021-05-19T13:29:51 Z |
Jasiekstrz |
Mecho (IOI09_mecho) |
C++17 |
|
442 ms |
9540 KB |
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int INF=1e9+7;
const int N=800;
struct Pos
{
int x,y;
Pos(int _x=0,int _y=0) : x(_x), y(_y) {};
bool operator==(const Pos &oth)
{
return (x==oth.x && y==oth.y);
}
vector<Pos> edges()
{
vector<Pos> tmp;
tmp.reserve(4);
for(auto dd:{make_pair(0,-1),make_pair(0,1),make_pair(-1,0),make_pair(1,0)})
tmp.push_back({x+dd.fi,y+dd.se});
return tmp;
}
};
bool fr[N+10][N+10];
queue<Pos> qq;
int bt[N+10][N+10];
pair<int,int> d[N+10][N+10];
bool ok(Pos start,Pos finish,int s,int time,int n)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
d[i][j]={INF,INF};
}
d[start.x][start.y]={time,0};
qq.push(start);
while(!qq.empty())
{
auto x=qq.front();
qq.pop();
vector<Pos> e=x.edges();
pair<int,int> tn=(d[x.x][x.y].se+1>=s ? make_pair(d[x.x][x.y].fi+1,0):
make_pair(d[x.x][x.y].fi,d[x.x][x.y].se+1));
for(auto v:e)
{
if((fr[v.x][v.y] || v==finish) && d[v.x][v.y].se==INF && bt[v.x][v.y]>tn.fi)
{
d[v.x][v.y]=tn;
qq.push(v);
}
}
}
return (d[finish.x][finish.y].fi!=INF);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,s;
Pos start,finish;
cin>>n>>s;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
bt[i][j]=INF;
char c;
cin>>c;
if(c=='T')
{
fr[i][j]=false;
}
else if(c=='G')
{
fr[i][j]=true;
}
else if(c=='M')
{
fr[i][j]=true;
start=Pos(i,j);
}
else if(c=='D')
{
fr[i][j]=false;
finish=Pos(i,j);
}
else if(c=='H')
{
fr[i][j]=false;
qq.push(Pos(i,j));
bt[i][j]=0;
}
}
}
while(!qq.empty())
{
Pos a=qq.front();
qq.pop();
vector<Pos> e=a.edges();
for(auto v:e)
{
if(fr[v.x][v.y] && bt[v.x][v.y]==INF)
{
bt[v.x][v.y]=bt[a.x][a.y]+1;
qq.push(v);
}
}
}
//for(int i=1;i<=n;i++)
//{
// for(int j=1;j<=n;j++)
// cerr<<bt[i][j]<<" ";
// cerr<<"\n";
//}
if(!ok(start,finish,s,0,n))
{
cout<<"-1\n";
return 0;
}
int bg=0,en=INF;
while(bg<en)
{
int mid=(bg+en+1)/2;
if(ok(start,finish,s,mid,n))
bg=mid;
else
en=mid-1;
}
cout<<bg<<"\n";
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 |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
327 ms |
9424 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
452 KB |
Output is correct |
12 |
Incorrect |
1 ms |
844 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
688 KB |
Output isn't correct |
14 |
Correct |
1 ms |
844 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 |
588 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
1 ms |
716 KB |
Output is correct |
24 |
Correct |
1 ms |
716 KB |
Output is correct |
25 |
Correct |
2 ms |
844 KB |
Output is correct |
26 |
Correct |
2 ms |
844 KB |
Output is correct |
27 |
Correct |
1 ms |
844 KB |
Output is correct |
28 |
Correct |
2 ms |
844 KB |
Output is correct |
29 |
Correct |
2 ms |
844 KB |
Output is correct |
30 |
Correct |
2 ms |
844 KB |
Output is correct |
31 |
Correct |
2 ms |
972 KB |
Output is correct |
32 |
Correct |
2 ms |
972 KB |
Output is correct |
33 |
Correct |
17 ms |
4064 KB |
Output is correct |
34 |
Correct |
21 ms |
4072 KB |
Output is correct |
35 |
Correct |
75 ms |
4068 KB |
Output is correct |
36 |
Correct |
19 ms |
4556 KB |
Output is correct |
37 |
Correct |
22 ms |
4504 KB |
Output is correct |
38 |
Correct |
97 ms |
4520 KB |
Output is correct |
39 |
Correct |
25 ms |
5172 KB |
Output is correct |
40 |
Correct |
29 ms |
5068 KB |
Output is correct |
41 |
Correct |
124 ms |
5168 KB |
Output is correct |
42 |
Correct |
30 ms |
5708 KB |
Output is correct |
43 |
Correct |
35 ms |
5632 KB |
Output is correct |
44 |
Correct |
157 ms |
5716 KB |
Output is correct |
45 |
Correct |
34 ms |
6220 KB |
Output is correct |
46 |
Correct |
41 ms |
6204 KB |
Output is correct |
47 |
Correct |
200 ms |
6392 KB |
Output is correct |
48 |
Correct |
42 ms |
6780 KB |
Output is correct |
49 |
Correct |
52 ms |
6784 KB |
Output is correct |
50 |
Correct |
232 ms |
6784 KB |
Output is correct |
51 |
Correct |
50 ms |
7420 KB |
Output is correct |
52 |
Correct |
63 ms |
7428 KB |
Output is correct |
53 |
Correct |
276 ms |
7536 KB |
Output is correct |
54 |
Correct |
59 ms |
8012 KB |
Output is correct |
55 |
Correct |
75 ms |
8012 KB |
Output is correct |
56 |
Correct |
346 ms |
8016 KB |
Output is correct |
57 |
Correct |
60 ms |
8524 KB |
Output is correct |
58 |
Correct |
72 ms |
8584 KB |
Output is correct |
59 |
Correct |
379 ms |
8644 KB |
Output is correct |
60 |
Correct |
69 ms |
9072 KB |
Output is correct |
61 |
Correct |
83 ms |
9100 KB |
Output is correct |
62 |
Correct |
442 ms |
9124 KB |
Output is correct |
63 |
Correct |
212 ms |
9156 KB |
Output is correct |
64 |
Correct |
370 ms |
9124 KB |
Output is correct |
65 |
Correct |
359 ms |
9284 KB |
Output is correct |
66 |
Correct |
260 ms |
9152 KB |
Output is correct |
67 |
Correct |
69 ms |
9156 KB |
Output is correct |
68 |
Correct |
113 ms |
9316 KB |
Output is correct |
69 |
Correct |
118 ms |
9136 KB |
Output is correct |
70 |
Correct |
103 ms |
9156 KB |
Output is correct |
71 |
Correct |
84 ms |
9136 KB |
Output is correct |
72 |
Incorrect |
88 ms |
9160 KB |
Output isn't correct |
73 |
Incorrect |
152 ms |
9420 KB |
Output isn't correct |
74 |
Correct |
247 ms |
9352 KB |
Output is correct |
75 |
Correct |
237 ms |
9412 KB |
Output is correct |
76 |
Correct |
221 ms |
9468 KB |
Output is correct |
77 |
Correct |
227 ms |
9468 KB |
Output is correct |
78 |
Correct |
84 ms |
9336 KB |
Output is correct |
79 |
Correct |
219 ms |
9540 KB |
Output is correct |
80 |
Correct |
203 ms |
9444 KB |
Output is correct |
81 |
Correct |
203 ms |
9412 KB |
Output is correct |
82 |
Correct |
196 ms |
9444 KB |
Output is correct |
83 |
Correct |
248 ms |
9280 KB |
Output is correct |
84 |
Correct |
274 ms |
9332 KB |
Output is correct |
85 |
Correct |
251 ms |
9540 KB |
Output is correct |
86 |
Correct |
292 ms |
9344 KB |
Output is correct |
87 |
Correct |
270 ms |
9412 KB |
Output is correct |
88 |
Correct |
260 ms |
9348 KB |
Output is correct |
89 |
Correct |
325 ms |
9348 KB |
Output is correct |
90 |
Correct |
298 ms |
9352 KB |
Output is correct |
91 |
Correct |
304 ms |
9284 KB |
Output is correct |
92 |
Correct |
298 ms |
9400 KB |
Output is correct |