# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
476430 |
2021-09-26T18:25:12 Z |
Morley |
Mecho (IOI09_mecho) |
C++14 |
|
49 ms |
4988 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvpi = vector<vector<pair<int,int>>>;
using vvb = vector<vector<bool>>;
using str = string;
using pi= pair<int,int>;
using pll = pair<ll,ll>;
using vpi = vector<pi>;
using ti = tuple<int,int,int>;
using vti = vector<ti>;
#define pb push_back
#define rs resize
#define mp make_pair
#define FOR(x,y,z) for(int x=y; x<z; x++)
#define F0R(x,z) for(int x=0; x<z; x++)
#define all(a) a.begin() , a.end()
ll mx = 1000000000000000000;
int inf = 2000000000;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n,s; cin >> n >> s;
vector<str> F(n);
for(int i=0;i<n;i++) cin >> F[i];
vvi hd(n,vi(n,inf));
queue<ti> Q;
for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(F[i][j]=='H') Q.push({i,j,0});
while(!Q.empty()) {
ti cur=Q.front(); Q.pop();
int i=get<0>(cur),j=get<1>(cur),d=get<2>(cur);
//cout << i << j << d << "\n";
if(d>=hd[i][j]) continue;
hd[i][j]=d;
if(i>0 && hd[i-1][j]==inf && (F[i-1][j]=='G' || F[i-1][j]=='M')) Q.push({i-1,j,d+1});
if(i<n-1 && hd[i+1][j]==inf && (F[i+1][j]=='G' || F[i+1][j]=='M')) Q.push({i+1,j,d+1});
if(j>0 && hd[i][j-1]==inf && (F[i][j-1]=='G' || F[i][j-1]=='M')) Q.push({i,j-1,d+1});
if(j<n-1 && hd[i][j+1]==inf && (F[i][j+1]=='G' || F[i][j+1]=='M')) Q.push({i,j+1,d+1});
}
//for(int i=0;i<n;i++) {for(int j=0;j<n;j++) if(hd[i][j]<inf) cout << hd[i][j]; else cout << "T"; cout << "\n";}
int lob=-1,upb=0;
while(lob<upb) {
int tst=(lob+upb+1)/2;
queue<ti> Qp;
for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(F[i][j]=='M') Qp.push({i,j,0});
bool good=false; vb vis(n*n,false);
while(!Qp.empty()) {
ti cur=Qp.front(); Qp.pop();
int i=get<0>(cur),j=get<1>(cur),d=get<2>(cur);
//cout << i << j << d << " ";
vis[i*n+j]=true;
if(F[i][j]=='D') {good=true; break;}
if(tst+d/s>=hd[i][j]) continue;
if(i>0 && !vis[(i-1)*n+j] && (F[i-1][j]=='G' || F[i-1][j]=='D')) {Qp.push({i-1,j,d+1}); vis[n*(i-1)+j]=true;}
if(i<n-1 && !vis[n*(i+1)+j] && (F[i+1][j]=='G' || F[i+1][j]=='D')) {Qp.push({i+1,j,d+1}); vis[n*(i+1)+j]=true;}
if(j>0 && !vis[n*i+j-1] && (F[i][j-1]=='G' || F[i][j-1]=='D')) {Qp.push({i,j-1,d+1}); vis[n*i+j-1]=true;}
if(j<n-1 && !vis[n*i+j+1] && (F[i][j+1]=='G' || F[i][j+1]=='D')) {Qp.push({i,j+1,d+1}); vis[n*i+j+1]=true;}
}
if(!good) upb=tst-1;
else lob=tst;
}
cout << upb;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
7 |
Incorrect |
37 ms |
4500 KB |
Output isn't correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
17 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
19 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
20 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
21 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
22 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
23 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
26 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
27 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
29 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
30 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
31 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
33 |
Incorrect |
2 ms |
844 KB |
Output isn't correct |
34 |
Incorrect |
2 ms |
844 KB |
Output isn't correct |
35 |
Incorrect |
7 ms |
1100 KB |
Output isn't correct |
36 |
Incorrect |
3 ms |
1100 KB |
Output isn't correct |
37 |
Incorrect |
2 ms |
1100 KB |
Output isn't correct |
38 |
Incorrect |
7 ms |
1324 KB |
Output isn't correct |
39 |
Incorrect |
3 ms |
1356 KB |
Output isn't correct |
40 |
Incorrect |
3 ms |
1356 KB |
Output isn't correct |
41 |
Incorrect |
9 ms |
1484 KB |
Output isn't correct |
42 |
Incorrect |
4 ms |
1612 KB |
Output isn't correct |
43 |
Incorrect |
4 ms |
1612 KB |
Output isn't correct |
44 |
Incorrect |
10 ms |
1844 KB |
Output isn't correct |
45 |
Incorrect |
5 ms |
1868 KB |
Output isn't correct |
46 |
Incorrect |
5 ms |
1868 KB |
Output isn't correct |
47 |
Incorrect |
12 ms |
2124 KB |
Output isn't correct |
48 |
Incorrect |
6 ms |
2124 KB |
Output isn't correct |
49 |
Incorrect |
6 ms |
2124 KB |
Output isn't correct |
50 |
Incorrect |
15 ms |
2508 KB |
Output isn't correct |
51 |
Incorrect |
7 ms |
2380 KB |
Output isn't correct |
52 |
Incorrect |
7 ms |
2380 KB |
Output isn't correct |
53 |
Incorrect |
17 ms |
2932 KB |
Output isn't correct |
54 |
Incorrect |
7 ms |
2764 KB |
Output isn't correct |
55 |
Incorrect |
8 ms |
2764 KB |
Output isn't correct |
56 |
Incorrect |
21 ms |
3240 KB |
Output isn't correct |
57 |
Incorrect |
9 ms |
3156 KB |
Output isn't correct |
58 |
Incorrect |
8 ms |
3148 KB |
Output isn't correct |
59 |
Incorrect |
23 ms |
3796 KB |
Output isn't correct |
60 |
Incorrect |
11 ms |
3532 KB |
Output isn't correct |
61 |
Incorrect |
10 ms |
3532 KB |
Output isn't correct |
62 |
Incorrect |
32 ms |
4264 KB |
Output isn't correct |
63 |
Correct |
48 ms |
3532 KB |
Output is correct |
64 |
Incorrect |
42 ms |
3532 KB |
Output isn't correct |
65 |
Incorrect |
39 ms |
3544 KB |
Output isn't correct |
66 |
Incorrect |
37 ms |
3676 KB |
Output isn't correct |
67 |
Correct |
32 ms |
3624 KB |
Output is correct |
68 |
Correct |
29 ms |
3592 KB |
Output is correct |
69 |
Incorrect |
29 ms |
3660 KB |
Output isn't correct |
70 |
Incorrect |
28 ms |
3584 KB |
Output isn't correct |
71 |
Incorrect |
28 ms |
3584 KB |
Output isn't correct |
72 |
Incorrect |
27 ms |
3592 KB |
Output isn't correct |
73 |
Incorrect |
37 ms |
4932 KB |
Output isn't correct |
74 |
Incorrect |
41 ms |
4968 KB |
Output isn't correct |
75 |
Incorrect |
37 ms |
4940 KB |
Output isn't correct |
76 |
Incorrect |
37 ms |
4980 KB |
Output isn't correct |
77 |
Incorrect |
42 ms |
4988 KB |
Output isn't correct |
78 |
Correct |
39 ms |
4812 KB |
Output is correct |
79 |
Incorrect |
45 ms |
4900 KB |
Output isn't correct |
80 |
Incorrect |
36 ms |
4812 KB |
Output isn't correct |
81 |
Incorrect |
37 ms |
4904 KB |
Output isn't correct |
82 |
Incorrect |
38 ms |
4804 KB |
Output isn't correct |
83 |
Correct |
39 ms |
4760 KB |
Output is correct |
84 |
Incorrect |
45 ms |
4760 KB |
Output isn't correct |
85 |
Incorrect |
41 ms |
4780 KB |
Output isn't correct |
86 |
Incorrect |
40 ms |
4684 KB |
Output isn't correct |
87 |
Incorrect |
39 ms |
4764 KB |
Output isn't correct |
88 |
Correct |
41 ms |
4556 KB |
Output is correct |
89 |
Incorrect |
49 ms |
4632 KB |
Output isn't correct |
90 |
Incorrect |
41 ms |
4556 KB |
Output isn't correct |
91 |
Incorrect |
40 ms |
4556 KB |
Output isn't correct |
92 |
Incorrect |
40 ms |
4556 KB |
Output isn't correct |