#include <bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
using namespace std;
int n,s;
int t[802][802];
char c[802][802];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
bool pos(int x,int y, int now){
for(int i = 0; i < 4; i++){
if(c[x + dx[i]][y + dy[i]]=='D'){
return 1;
}
if(c[x + dx[i]][y + dy[i]]=='G'&&t[x + dx[i]][y + dy[i]] > now + 1){
c[x + dx[i]][y + dy[i]]=='T';
if(pos(x + dx[i],y + dy[i],now+1)){
c[x + dx[i]][y + dy[i]]=='G';
return 1;
};
c[x + dx[i]][y + dy[i]]=='G';
}
}
return 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int i,j,xx,yy;
cin>>n>>s;
queue<pair<int, int > > q;
for(i = 1; i <= n; i++){
for(j = 1; j <= n; j++){
cin>>c[i][j];
if(c[i][j]=='H'){
q.push(mp(i,j));
} else if(c[i][j]=='M'){
xx=i;
yy=j;
}
}
}
int x,y;
while(!q.empty()){
x=q.front().ff;
y=q.front().ss;
q.pop();
for(i=0;i<4;i++){
if(c[x + dx[i]][y + dy[i]]=='G'&&t[x + dx[i]][y + dy[i]]==0){
t[x + dx[i]][y + dy[i]] = t[x][y]+s;
q.push(mp(x + dx[i] , y + dy[i]));
}
}
}
int l = -1 , r = 1e9,m;
while(l + 1 != r){
m = (l + r) / 2;
if(pos(xx,yy,m)){
l = m;
} else {
r = m;
}
}
cout<<l/s;
}
Compilation message
mecho.cpp: In function 'bool pos(int, int, int)':
mecho.cpp:18:27: warning: statement has no effect [-Wunused-value]
c[x + dx[i]][y + dy[i]]=='T';
~~~~~~~~~~~~~~~~~~~~~~~^~~~~
mecho.cpp:20:28: warning: statement has no effect [-Wunused-value]
c[x + dx[i]][y + dy[i]]=='G';
~~~~~~~~~~~~~~~~~~~~~~~^~~~~
mecho.cpp:23:27: warning: statement has no effect [-Wunused-value]
c[x + dx[i]][y + dy[i]]=='G';
~~~~~~~~~~~~~~~~~~~~~~~^~~~~
mecho.cpp: In function 'int main()':
mecho.cpp:62:9: warning: 'yy' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(pos(xx,yy,m)){
~~~^~~~~~~~~
mecho.cpp:62:9: warning: 'xx' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
492 KB |
Output is correct |
3 |
Correct |
3 ms |
572 KB |
Output is correct |
4 |
Correct |
3 ms |
572 KB |
Output is correct |
5 |
Correct |
5 ms |
572 KB |
Output is correct |
6 |
Correct |
117 ms |
624 KB |
Output is correct |
7 |
Execution timed out |
1081 ms |
4576 KB |
Time limit exceeded |
8 |
Correct |
3 ms |
4576 KB |
Output is correct |
9 |
Correct |
4 ms |
4576 KB |
Output is correct |
10 |
Correct |
2 ms |
4576 KB |
Output is correct |
11 |
Correct |
2 ms |
4576 KB |
Output is correct |
12 |
Incorrect |
4 ms |
4576 KB |
Output isn't correct |
13 |
Execution timed out |
1071 ms |
4576 KB |
Time limit exceeded |
14 |
Execution timed out |
1081 ms |
4576 KB |
Time limit exceeded |
15 |
Execution timed out |
1072 ms |
4576 KB |
Time limit exceeded |
16 |
Execution timed out |
1083 ms |
4576 KB |
Time limit exceeded |
17 |
Execution timed out |
1054 ms |
4576 KB |
Time limit exceeded |
18 |
Execution timed out |
1076 ms |
4576 KB |
Time limit exceeded |
19 |
Execution timed out |
1002 ms |
4576 KB |
Time limit exceeded |
20 |
Execution timed out |
1090 ms |
4576 KB |
Time limit exceeded |
21 |
Execution timed out |
1052 ms |
4576 KB |
Time limit exceeded |
22 |
Execution timed out |
1054 ms |
4576 KB |
Time limit exceeded |
23 |
Execution timed out |
1037 ms |
4576 KB |
Time limit exceeded |
24 |
Execution timed out |
1072 ms |
4576 KB |
Time limit exceeded |
25 |
Execution timed out |
1090 ms |
4576 KB |
Time limit exceeded |
26 |
Execution timed out |
1080 ms |
4576 KB |
Time limit exceeded |
27 |
Execution timed out |
1089 ms |
4576 KB |
Time limit exceeded |
28 |
Execution timed out |
1082 ms |
4576 KB |
Time limit exceeded |
29 |
Execution timed out |
1058 ms |
4576 KB |
Time limit exceeded |
30 |
Execution timed out |
1068 ms |
4576 KB |
Time limit exceeded |
31 |
Execution timed out |
1048 ms |
4576 KB |
Time limit exceeded |
32 |
Execution timed out |
1079 ms |
4576 KB |
Time limit exceeded |
33 |
Execution timed out |
1086 ms |
4576 KB |
Time limit exceeded |
34 |
Execution timed out |
1057 ms |
5000 KB |
Time limit exceeded |
35 |
Execution timed out |
1082 ms |
8328 KB |
Time limit exceeded |
36 |
Execution timed out |
1070 ms |
8328 KB |
Time limit exceeded |
37 |
Execution timed out |
1071 ms |
8328 KB |
Time limit exceeded |
38 |
Execution timed out |
1063 ms |
8328 KB |
Time limit exceeded |
39 |
Execution timed out |
1069 ms |
8328 KB |
Time limit exceeded |
40 |
Execution timed out |
1082 ms |
8328 KB |
Time limit exceeded |
41 |
Execution timed out |
1072 ms |
8328 KB |
Time limit exceeded |
42 |
Execution timed out |
1087 ms |
8328 KB |
Time limit exceeded |
43 |
Execution timed out |
1085 ms |
8328 KB |
Time limit exceeded |
44 |
Execution timed out |
1075 ms |
8328 KB |
Time limit exceeded |
45 |
Execution timed out |
1078 ms |
8328 KB |
Time limit exceeded |
46 |
Execution timed out |
1069 ms |
8328 KB |
Time limit exceeded |
47 |
Execution timed out |
1082 ms |
8328 KB |
Time limit exceeded |
48 |
Execution timed out |
1061 ms |
8328 KB |
Time limit exceeded |
49 |
Execution timed out |
1064 ms |
8840 KB |
Time limit exceeded |
50 |
Execution timed out |
1068 ms |
8840 KB |
Time limit exceeded |
51 |
Execution timed out |
1073 ms |
8840 KB |
Time limit exceeded |
52 |
Execution timed out |
1085 ms |
10888 KB |
Time limit exceeded |
53 |
Execution timed out |
1093 ms |
10888 KB |
Time limit exceeded |
54 |
Execution timed out |
1063 ms |
10888 KB |
Time limit exceeded |
55 |
Execution timed out |
1075 ms |
10888 KB |
Time limit exceeded |
56 |
Execution timed out |
1078 ms |
27016 KB |
Time limit exceeded |
57 |
Execution timed out |
1083 ms |
27016 KB |
Time limit exceeded |
58 |
Execution timed out |
1077 ms |
27016 KB |
Time limit exceeded |
59 |
Execution timed out |
1085 ms |
27016 KB |
Time limit exceeded |
60 |
Execution timed out |
1077 ms |
27016 KB |
Time limit exceeded |
61 |
Execution timed out |
1067 ms |
27016 KB |
Time limit exceeded |
62 |
Execution timed out |
1063 ms |
27016 KB |
Time limit exceeded |
63 |
Execution timed out |
1081 ms |
27016 KB |
Time limit exceeded |
64 |
Execution timed out |
1088 ms |
27016 KB |
Time limit exceeded |
65 |
Execution timed out |
1078 ms |
27016 KB |
Time limit exceeded |
66 |
Execution timed out |
1073 ms |
27016 KB |
Time limit exceeded |
67 |
Execution timed out |
1081 ms |
27016 KB |
Time limit exceeded |
68 |
Execution timed out |
1084 ms |
27016 KB |
Time limit exceeded |
69 |
Execution timed out |
1073 ms |
27016 KB |
Time limit exceeded |
70 |
Execution timed out |
1079 ms |
27016 KB |
Time limit exceeded |
71 |
Execution timed out |
1045 ms |
27016 KB |
Time limit exceeded |
72 |
Execution timed out |
1043 ms |
27016 KB |
Time limit exceeded |
73 |
Execution timed out |
1066 ms |
27016 KB |
Time limit exceeded |
74 |
Execution timed out |
1078 ms |
27016 KB |
Time limit exceeded |
75 |
Execution timed out |
1078 ms |
27016 KB |
Time limit exceeded |
76 |
Execution timed out |
1075 ms |
27016 KB |
Time limit exceeded |
77 |
Execution timed out |
1090 ms |
27016 KB |
Time limit exceeded |
78 |
Execution timed out |
1081 ms |
27016 KB |
Time limit exceeded |
79 |
Execution timed out |
1086 ms |
27016 KB |
Time limit exceeded |
80 |
Execution timed out |
1083 ms |
27016 KB |
Time limit exceeded |
81 |
Execution timed out |
1071 ms |
27016 KB |
Time limit exceeded |
82 |
Execution timed out |
1077 ms |
27016 KB |
Time limit exceeded |
83 |
Execution timed out |
1088 ms |
27016 KB |
Time limit exceeded |
84 |
Execution timed out |
1074 ms |
27016 KB |
Time limit exceeded |
85 |
Execution timed out |
1084 ms |
27016 KB |
Time limit exceeded |
86 |
Execution timed out |
1085 ms |
27016 KB |
Time limit exceeded |
87 |
Execution timed out |
1080 ms |
27016 KB |
Time limit exceeded |
88 |
Execution timed out |
1075 ms |
27016 KB |
Time limit exceeded |
89 |
Execution timed out |
1081 ms |
27016 KB |
Time limit exceeded |
90 |
Execution timed out |
1081 ms |
27016 KB |
Time limit exceeded |
91 |
Execution timed out |
1054 ms |
27016 KB |
Time limit exceeded |
92 |
Execution timed out |
1083 ms |
27016 KB |
Time limit exceeded |