# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
996446 |
2024-06-10T15:42:50 Z |
ramalzaher |
Mecho (IOI09_mecho) |
C++14 |
|
374 ms |
9564 KB |
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std ;
const int N = 801 ;
const int T = 1000 ;
int n , s;
char a[N][N] ;
int dis[N][N] , vis[N][N] ;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
bool valid(int x , int y ) {
return x >= 0 && x < n && y >= 0 && y < n &&
(a[x][y] == 'G' || a[x][y] == 'M');}
void bfs(vector<int> startx , vector<int> starty ){
queue<pair<int,int>> q;
for (int i = 0; i < startx.size() ; i++)
{
q.push({startx[i] , starty[i] });
vis[startx[i]][starty[i]] = 1 ;
dis[startx[i]][starty[i]] = 0 ;
}
while(q.size()){
pair<int,int> p = q.front() ;
int x = p.first;
int y = p.second ;
q.pop() ;
for (int i = 0; i < 4; i++)
{
int newx = x+dx[i];
int newy = y+dy[i];
if(valid(newx , newy) && vis[newx][newy] == 0){
q.push({newx , newy });
dis[newx][newy] = dis[x][y]+1;
vis[newx][newy] = 1 ;
}
}
}
}
bool viss[N][N] ;int diss[N][N];
int homex , homey ;
bool bfss(int startx ,int starty , int TT ) {
viss[startx][starty] = 1 ;
diss[startx][starty] = 0 ;
queue<pair<int,int>> q;
q.push({startx , starty });
if(dis[startx][starty] <= TT) { q.pop() ; }
while(q.size()){
auto &[x,y] = q.front() ;
q.pop();
for (int i = 0; i < 4; i++)
{
int newx = x+dx[i];
int newy = y+dy[i];
if(viss[newx][newy] ==0 && valid(newx, newy) && (dis[newx][newy]-TT) > (((diss[x][y]+1)/s) ) ) {
q.push( { newx, newy } );
diss[newx][newy] = diss[x][y]+1 ;
viss[newx][newy]= 1;
}
}
}
for (int i = 0; i < 4; i++)
{
int nx = homex+dx[i]; int ny=homey+dy[i] ;
if(valid(nx,ny)&& ( diss[nx][ny]/s ) < ( dis[nx][ny]-TT ) && viss[nx][ny] )return 1 ;
}
return 0 ;
}
void cls(){
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= n ; j++)
{
viss[i][j]=vis[i][j]=0;
diss[i][j]=0 ;
dis[i][j]= 0 ;
}
}
}
main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> s ; int mx , my ;
vector<int> stx , sty ;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n ; j++)
{
cin >> a[i][j] ;
if(a[i][j]=='H'){
stx.push_back(i);
sty.push_back(j);
}else if(a[i][j]=='M'){mx=i;my=j;}else if(a[i][j]=='D'){homex=i;homey=j;}
}
}
int l =0 , r = n*n ;
while(l <= r )
{
cls();
int mid = (l+r)/2 ;
bfs(stx,sty);
if(bfss(mx,my,mid)) {
l = mid + 1;
}else r = mid - 1;
}
cout<<l-1<<endl;
return 0 ;
}
Compilation message
mecho.cpp: In function 'void bfs(std::vector<int>, std::vector<int>)':
mecho.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < startx.size() ; i++)
| ~~^~~~~~~~~~~~~~~
mecho.cpp: In function 'bool bfss(int, int, int)':
mecho.cpp:50:7: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
50 | auto &[x,y] = q.front() ;
| ^
mecho.cpp: In function 'void cls()':
mecho.cpp:76:22: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
76 | viss[i][j]=vis[i][j]=0;
| ~~~~~~~~~^~
mecho.cpp: At global scope:
mecho.cpp:83:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
83 | main(){
| ^~~~
mecho.cpp: In function 'int main()':
mecho.cpp:104:8: warning: 'my' may be used uninitialized in this function [-Wmaybe-uninitialized]
104 | if(bfss(mx,my,mid)) {
| ~~~~^~~~~~~~~~~
mecho.cpp:104:8: warning: 'mx' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
251 ms |
9348 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
8796 KB |
Output is correct |
13 |
Correct |
1 ms |
6748 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6488 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6748 KB |
Output is correct |
24 |
Correct |
1 ms |
6748 KB |
Output is correct |
25 |
Correct |
1 ms |
8796 KB |
Output is correct |
26 |
Correct |
1 ms |
8796 KB |
Output is correct |
27 |
Correct |
1 ms |
8796 KB |
Output is correct |
28 |
Correct |
2 ms |
8792 KB |
Output is correct |
29 |
Correct |
2 ms |
8796 KB |
Output is correct |
30 |
Correct |
2 ms |
8796 KB |
Output is correct |
31 |
Correct |
2 ms |
8796 KB |
Output is correct |
32 |
Correct |
2 ms |
8844 KB |
Output is correct |
33 |
Correct |
19 ms |
8904 KB |
Output is correct |
34 |
Correct |
18 ms |
8796 KB |
Output is correct |
35 |
Correct |
37 ms |
8796 KB |
Output is correct |
36 |
Correct |
25 ms |
8796 KB |
Output is correct |
37 |
Correct |
24 ms |
8796 KB |
Output is correct |
38 |
Correct |
45 ms |
8796 KB |
Output is correct |
39 |
Correct |
31 ms |
8796 KB |
Output is correct |
40 |
Correct |
30 ms |
8792 KB |
Output is correct |
41 |
Correct |
61 ms |
8952 KB |
Output is correct |
42 |
Correct |
43 ms |
8796 KB |
Output is correct |
43 |
Correct |
43 ms |
9052 KB |
Output is correct |
44 |
Correct |
74 ms |
8828 KB |
Output is correct |
45 |
Correct |
51 ms |
9052 KB |
Output is correct |
46 |
Correct |
48 ms |
9048 KB |
Output is correct |
47 |
Correct |
90 ms |
9052 KB |
Output is correct |
48 |
Correct |
56 ms |
9052 KB |
Output is correct |
49 |
Correct |
67 ms |
9068 KB |
Output is correct |
50 |
Correct |
106 ms |
9048 KB |
Output is correct |
51 |
Correct |
86 ms |
9052 KB |
Output is correct |
52 |
Correct |
63 ms |
9048 KB |
Output is correct |
53 |
Correct |
141 ms |
9116 KB |
Output is correct |
54 |
Correct |
85 ms |
9148 KB |
Output is correct |
55 |
Correct |
72 ms |
9052 KB |
Output is correct |
56 |
Correct |
151 ms |
9156 KB |
Output is correct |
57 |
Correct |
95 ms |
9204 KB |
Output is correct |
58 |
Correct |
82 ms |
9052 KB |
Output is correct |
59 |
Correct |
177 ms |
9048 KB |
Output is correct |
60 |
Correct |
110 ms |
9048 KB |
Output is correct |
61 |
Correct |
102 ms |
9052 KB |
Output is correct |
62 |
Correct |
199 ms |
9052 KB |
Output is correct |
63 |
Correct |
303 ms |
9052 KB |
Output is correct |
64 |
Correct |
374 ms |
9236 KB |
Output is correct |
65 |
Correct |
324 ms |
9048 KB |
Output is correct |
66 |
Correct |
307 ms |
9052 KB |
Output is correct |
67 |
Correct |
302 ms |
9052 KB |
Output is correct |
68 |
Correct |
293 ms |
9052 KB |
Output is correct |
69 |
Correct |
306 ms |
9268 KB |
Output is correct |
70 |
Correct |
315 ms |
9052 KB |
Output is correct |
71 |
Correct |
312 ms |
9308 KB |
Output is correct |
72 |
Correct |
284 ms |
9052 KB |
Output is correct |
73 |
Correct |
244 ms |
9564 KB |
Output is correct |
74 |
Correct |
250 ms |
9560 KB |
Output is correct |
75 |
Correct |
273 ms |
9564 KB |
Output is correct |
76 |
Correct |
263 ms |
9560 KB |
Output is correct |
77 |
Correct |
257 ms |
9560 KB |
Output is correct |
78 |
Correct |
266 ms |
9512 KB |
Output is correct |
79 |
Correct |
244 ms |
9516 KB |
Output is correct |
80 |
Correct |
247 ms |
9552 KB |
Output is correct |
81 |
Correct |
257 ms |
9304 KB |
Output is correct |
82 |
Correct |
246 ms |
9304 KB |
Output is correct |
83 |
Correct |
269 ms |
9304 KB |
Output is correct |
84 |
Correct |
260 ms |
9304 KB |
Output is correct |
85 |
Correct |
272 ms |
9352 KB |
Output is correct |
86 |
Correct |
259 ms |
9308 KB |
Output is correct |
87 |
Correct |
258 ms |
9468 KB |
Output is correct |
88 |
Correct |
261 ms |
9308 KB |
Output is correct |
89 |
Correct |
264 ms |
9308 KB |
Output is correct |
90 |
Correct |
274 ms |
9304 KB |
Output is correct |
91 |
Correct |
268 ms |
9564 KB |
Output is correct |
92 |
Correct |
272 ms |
9412 KB |
Output is correct |