# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
65725 |
2018-08-08T13:55:07 Z |
TuGSGeReL |
Mecho (IOI09_mecho) |
C++14 |
|
1000 ms |
13048 KB |
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back
#define ss second
#define ff first
#define ext exit(0)
using namespace std;
int n,s,l,r,x,y,zu[801][801],bo[801][801],ax,ay;
char c[801][801];
void dfs(int i, int j){
queue<pair<pair<int,int>,int> >q;
memset(bo,0,sizeof bo);
q.push(mp(mp(i,j),0));
bo[i][j]=1;
zu[i][j]=0;
while(!q.empty()){
int ii=q.front().ff.ff,jj=q.front().ff.ss,zz=q.front().ss;
if(ii>1 && c[ii-1][jj]!='T' && c[ii-1][jj]!='D' && !bo[ii-1][jj]){
bo[ii-1][jj]=1;
zu[ii-1][jj]=min(zu[ii-1][jj],zz+1);
q.push(mp(mp(ii-1,jj),zz+1));
}
if(ii<n && c[ii+1][jj]!='T' && c[ii+1][jj]!='D' && !bo[ii+1][jj]){
bo[ii+1][jj]=1;
zu[ii+1][jj]=min(zu[ii+1][jj],zz+1);
q.push(mp(mp(ii+1,jj),zz+1));
}
if(jj>1 && c[ii][jj-1]!='T' && c[ii][jj-1]!='D' && !bo[ii][jj-1]){
bo[ii][jj-1]=1;
zu[ii][jj-1]=min(zu[ii][jj-1],zz+1);
q.push(mp(mp(ii,jj-1),zz+1));
}
if(jj<n && c[ii][jj+1]!='T' && c[ii][jj+1]!='D' && !bo[ii][jj+1]){
bo[ii][jj+1]=1;
zu[ii][jj+1]=min(zu[ii][jj+1],zz+1);
q.push(mp(mp(ii,jj+1),zz+1));
}
q.pop();
}
}
bool can(int k){
queue<pair<pair<int,int>,pair<int,int> > >q;
memset(bo,0,sizeof bo);
q.push(mp(mp(x,y),mp(k,0)));
bo[x][y]=1;
while(!q.empty()){
int xx=q.front().ff.ff,yy=q.front().ff.ss,kk=q.front().ss.ff,zz=q.front().ss.ss;
if(zz==s) zz=0,kk++;
else zz++;
if(xx>1 && c[xx-1][yy]!='T' && !bo[xx-1][yy] && zu[xx-1][yy]>kk){
bo[xx-1][yy]=1;
q.push(mp(mp(xx-1,yy),mp(kk,zz)));
}
if(xx<n && c[xx+1][yy]!='T' && !bo[xx+1][yy] && zu[xx+1][yy]>kk){
bo[xx+1][yy]=1;
q.push(mp(mp(xx+1,yy),mp(kk,zz)));
}
if(yy>1 && c[xx][yy-1]!='T' && !bo[xx][yy-1] && zu[xx][yy-1]>kk){
bo[xx][yy-1]=1;
q.push(mp(mp(xx,yy-1),mp(kk,zz)));
}
if(yy<n && c[xx][yy+1]!='T' && !bo[xx][yy+1] && zu[xx][yy+1]>kk){
bo[xx][yy+1]=1;
q.push(mp(mp(xx,yy+1),mp(kk,zz)));
}
q.pop();
}
if(bo[ax][ay]) return 1;
return 0;
}
int main (){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>s;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>c[i][j];
if(c[i][j]=='M') x=i,y=j;
if(c[i][j]=='D') ax=i,ay=j;
zu[i][j]=1e9;
}
}
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(c[i][j]=='H') dfs(i,j);
l=0,r=640000;
while(l+1<r){
ll mid=(l+r)/2;
if(can(mid)) l=mid;
else r=mid;
}
cout<<l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
2936 KB |
Output isn't correct |
2 |
Incorrect |
7 ms |
2936 KB |
Output isn't correct |
3 |
Incorrect |
7 ms |
3000 KB |
Output isn't correct |
4 |
Incorrect |
7 ms |
3000 KB |
Output isn't correct |
5 |
Correct |
7 ms |
3084 KB |
Output is correct |
6 |
Incorrect |
8 ms |
3084 KB |
Output isn't correct |
7 |
Execution timed out |
1082 ms |
6832 KB |
Time limit exceeded |
8 |
Incorrect |
9 ms |
6832 KB |
Output isn't correct |
9 |
Correct |
9 ms |
6832 KB |
Output is correct |
10 |
Incorrect |
9 ms |
6832 KB |
Output isn't correct |
11 |
Incorrect |
8 ms |
6832 KB |
Output isn't correct |
12 |
Incorrect |
7 ms |
6832 KB |
Output isn't correct |
13 |
Incorrect |
36 ms |
6832 KB |
Output isn't correct |
14 |
Incorrect |
34 ms |
6832 KB |
Output isn't correct |
15 |
Incorrect |
9 ms |
6832 KB |
Output isn't correct |
16 |
Correct |
7 ms |
6832 KB |
Output is correct |
17 |
Incorrect |
7 ms |
6832 KB |
Output isn't correct |
18 |
Correct |
8 ms |
6832 KB |
Output is correct |
19 |
Incorrect |
9 ms |
6832 KB |
Output isn't correct |
20 |
Correct |
7 ms |
6832 KB |
Output is correct |
21 |
Incorrect |
7 ms |
6832 KB |
Output isn't correct |
22 |
Correct |
7 ms |
6832 KB |
Output is correct |
23 |
Incorrect |
9 ms |
6832 KB |
Output isn't correct |
24 |
Correct |
7 ms |
6832 KB |
Output is correct |
25 |
Incorrect |
8 ms |
6832 KB |
Output isn't correct |
26 |
Correct |
9 ms |
6832 KB |
Output is correct |
27 |
Incorrect |
8 ms |
6832 KB |
Output isn't correct |
28 |
Correct |
8 ms |
6832 KB |
Output is correct |
29 |
Incorrect |
7 ms |
6832 KB |
Output isn't correct |
30 |
Correct |
9 ms |
6832 KB |
Output is correct |
31 |
Incorrect |
7 ms |
6832 KB |
Output isn't correct |
32 |
Correct |
8 ms |
6832 KB |
Output is correct |
33 |
Incorrect |
13 ms |
6832 KB |
Output isn't correct |
34 |
Correct |
14 ms |
6832 KB |
Output is correct |
35 |
Correct |
36 ms |
6832 KB |
Output is correct |
36 |
Incorrect |
14 ms |
6832 KB |
Output isn't correct |
37 |
Correct |
16 ms |
6832 KB |
Output is correct |
38 |
Correct |
42 ms |
6832 KB |
Output is correct |
39 |
Incorrect |
13 ms |
6832 KB |
Output isn't correct |
40 |
Correct |
19 ms |
6864 KB |
Output is correct |
41 |
Correct |
61 ms |
7260 KB |
Output is correct |
42 |
Incorrect |
17 ms |
7588 KB |
Output isn't correct |
43 |
Correct |
22 ms |
7836 KB |
Output is correct |
44 |
Correct |
79 ms |
8084 KB |
Output is correct |
45 |
Incorrect |
21 ms |
8460 KB |
Output isn't correct |
46 |
Correct |
25 ms |
8756 KB |
Output is correct |
47 |
Correct |
81 ms |
9188 KB |
Output is correct |
48 |
Incorrect |
23 ms |
9604 KB |
Output isn't correct |
49 |
Correct |
25 ms |
9960 KB |
Output is correct |
50 |
Correct |
110 ms |
10452 KB |
Output is correct |
51 |
Incorrect |
23 ms |
10928 KB |
Output isn't correct |
52 |
Correct |
29 ms |
11348 KB |
Output is correct |
53 |
Correct |
128 ms |
11896 KB |
Output is correct |
54 |
Incorrect |
26 ms |
12308 KB |
Output isn't correct |
55 |
Correct |
34 ms |
12308 KB |
Output is correct |
56 |
Correct |
147 ms |
12308 KB |
Output is correct |
57 |
Incorrect |
27 ms |
12484 KB |
Output isn't correct |
58 |
Correct |
41 ms |
12484 KB |
Output is correct |
59 |
Correct |
160 ms |
12544 KB |
Output is correct |
60 |
Incorrect |
30 ms |
12676 KB |
Output isn't correct |
61 |
Correct |
41 ms |
12776 KB |
Output is correct |
62 |
Correct |
173 ms |
12776 KB |
Output is correct |
63 |
Execution timed out |
1073 ms |
12776 KB |
Time limit exceeded |
64 |
Execution timed out |
1069 ms |
12776 KB |
Time limit exceeded |
65 |
Execution timed out |
1077 ms |
12776 KB |
Time limit exceeded |
66 |
Execution timed out |
1082 ms |
12776 KB |
Time limit exceeded |
67 |
Execution timed out |
1084 ms |
12776 KB |
Time limit exceeded |
68 |
Execution timed out |
1079 ms |
12776 KB |
Time limit exceeded |
69 |
Execution timed out |
1088 ms |
12776 KB |
Time limit exceeded |
70 |
Execution timed out |
1088 ms |
12776 KB |
Time limit exceeded |
71 |
Execution timed out |
1090 ms |
12792 KB |
Time limit exceeded |
72 |
Execution timed out |
1085 ms |
12792 KB |
Time limit exceeded |
73 |
Execution timed out |
1088 ms |
12792 KB |
Time limit exceeded |
74 |
Execution timed out |
1079 ms |
12792 KB |
Time limit exceeded |
75 |
Execution timed out |
1080 ms |
12792 KB |
Time limit exceeded |
76 |
Execution timed out |
1087 ms |
12792 KB |
Time limit exceeded |
77 |
Execution timed out |
1082 ms |
12792 KB |
Time limit exceeded |
78 |
Execution timed out |
1064 ms |
12792 KB |
Time limit exceeded |
79 |
Execution timed out |
1084 ms |
12792 KB |
Time limit exceeded |
80 |
Execution timed out |
1076 ms |
12792 KB |
Time limit exceeded |
81 |
Execution timed out |
1078 ms |
12792 KB |
Time limit exceeded |
82 |
Execution timed out |
1079 ms |
12792 KB |
Time limit exceeded |
83 |
Execution timed out |
1087 ms |
12792 KB |
Time limit exceeded |
84 |
Execution timed out |
1082 ms |
12792 KB |
Time limit exceeded |
85 |
Execution timed out |
1082 ms |
12792 KB |
Time limit exceeded |
86 |
Execution timed out |
1080 ms |
12792 KB |
Time limit exceeded |
87 |
Execution timed out |
1069 ms |
13048 KB |
Time limit exceeded |
88 |
Execution timed out |
1083 ms |
13048 KB |
Time limit exceeded |
89 |
Execution timed out |
1078 ms |
13048 KB |
Time limit exceeded |
90 |
Execution timed out |
1078 ms |
13048 KB |
Time limit exceeded |
91 |
Execution timed out |
1070 ms |
13048 KB |
Time limit exceeded |
92 |
Execution timed out |
1083 ms |
13048 KB |
Time limit exceeded |