# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1039363 |
2024-07-30T19:04:06 Z |
Ludissey |
Mecho (IOI09_mecho) |
C++17 |
|
1000 ms |
12936 KB |
#include <bits/stdc++.h>
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
using namespace std;
vector<vector<bool>> visited;
vector<vector<int>> dist;
vector<vector<char>> grid;
vector<vector<int>> beeT;
pair<int,int> home;
pair<int,int> bear;
int N,S;
bool f(int t){
priority_queue<pair<int,pair<int,int>>> q;
visited.clear();
dist.clear();
visited.resize(N,vector<bool>(N,false));
dist.resize(N,vector<int>(N,1e9));
dist[bear.first][bear.second]=t*S;
q.push({-t*S,bear});
while(!q.empty()){
int x=q.top().second.first,y=q.top().second.second; q.pop();
if(visited[x][y]) continue;
visited[x][y]=true;
if(x-1>=0&&(grid[x-1][y]=='G'||grid[x-1][y]=='M'||grid[x-1][y]=='D')&&dist[x][y]+1<dist[x-1][y]&&((dist[x][y]+1)/S<beeT[x][y]||grid[x-1][y]!='D')){
dist[x-1][y]=dist[x][y]+1;
q.push({-dist[x-1][y], {x-1,y}});
}
if(x+1<N&&(grid[x+1][y]=='G'||grid[x+1][y]=='M'||grid[x+1][y]=='D')&&dist[x][y]+1<dist[x+1][y]&&((dist[x][y]+1)/S<beeT[x][y]||grid[x+1][y]!='D')){
dist[x+1][y]=dist[x][y]+1;
q.push({-dist[x+1][y], {x+1,y}});
}
if(y-1>=0&&(grid[x][y-1]=='G'||grid[x][y-1]=='M'||grid[x][y-1]=='D')&&dist[x][y]+1<dist[x][y-1]&&((dist[x][y]+1)/S<beeT[x][y]||grid[x][y-1]!='D')){
dist[x][y-1]=dist[x][y]+1;
q.push({-dist[x][y-1], {x,y-1}});
}
if(y+1<N&&(grid[x][y+1]=='G'||grid[x][y+1]=='M'||grid[x][y+1]=='D')&&dist[x][y]+1<dist[x][y+1]&&((dist[x][y]+1)/S<beeT[x][y]||grid[x][y+1]=='D')){
dist[x][y+1]=dist[x][y]+1;
q.push({-dist[x][y+1], {x,y+1}});
}
}
return visited[home.first][home.second];
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> N >> S;
grid.resize(N,vector<char>(N));
visited.resize(N,vector<bool>(N,false));
for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) cin >> grid[i][j]; }
for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++){
if(grid[i][j]=='M') bear={i,j};
else if(grid[i][j]=='D') home={i,j};
}
}
beeT.resize(N,vector<int>(N,1e9));
priority_queue<pair<int,pair<int,int>>> q;
for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) if(grid[i][j]=='H') { q.push({0,{i,j}}); beeT[i][j]=0; }}
while(!q.empty()){
int x=q.top().second.first,y=q.top().second.second; q.pop();
if(visited[x][y]) continue;
visited[x][y]=true;
if(x-1>=0&&(grid[x-1][y]!='T'||grid[x-1][y]!='D')&&beeT[x][y]+1<beeT[x-1][y]){
beeT[x-1][y]=beeT[x][y]+1;
q.push({-beeT[x-1][y], {x-1,y}});
}
if(x+1<N&&(grid[x+1][y]!='T'||grid[x+1][y]!='D')&&beeT[x][y]+1<beeT[x+1][y]){
beeT[x+1][y]=beeT[x][y]+1;
q.push({-beeT[x+1][y], {x+1,y}});
}
if(y-1>=0&&(grid[x][y-1]!='T'||grid[x][y-1]!='D')&&beeT[x][y]+1<beeT[x][y-1]){
beeT[x][y-1]=beeT[x][y]+1;
q.push({-beeT[x][y-1], {x,y-1}});
}
if(y+1<N&&(grid[x][y+1]!='T'||grid[x][y+1]!='D')&&beeT[x][y]+1<beeT[x][y+1]){
beeT[x][y+1]=beeT[x][y]+1;
q.push({-beeT[x][y+1], {x,y+1}});
}
}
int l=0,r=1e9;
while(l<r){
int mid=(l+r+1)/2;
if(f(mid)){
l=mid;
}else{
r=mid-1;
}
}
cout << l << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Execution timed out |
1091 ms |
12296 KB |
Time limit exceeded |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
452 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
20 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
29 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
30 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
33 |
Incorrect |
21 ms |
2700 KB |
Output isn't correct |
34 |
Incorrect |
21 ms |
2704 KB |
Output isn't correct |
35 |
Incorrect |
49 ms |
2704 KB |
Output isn't correct |
36 |
Incorrect |
24 ms |
3436 KB |
Output isn't correct |
37 |
Incorrect |
27 ms |
3452 KB |
Output isn't correct |
38 |
Incorrect |
69 ms |
3348 KB |
Output isn't correct |
39 |
Incorrect |
31 ms |
4232 KB |
Output isn't correct |
40 |
Incorrect |
33 ms |
4208 KB |
Output isn't correct |
41 |
Incorrect |
103 ms |
4456 KB |
Output isn't correct |
42 |
Incorrect |
39 ms |
5080 KB |
Output isn't correct |
43 |
Incorrect |
43 ms |
5072 KB |
Output isn't correct |
44 |
Incorrect |
78 ms |
4984 KB |
Output isn't correct |
45 |
Incorrect |
45 ms |
5992 KB |
Output isn't correct |
46 |
Incorrect |
50 ms |
6008 KB |
Output isn't correct |
47 |
Incorrect |
115 ms |
5984 KB |
Output isn't correct |
48 |
Incorrect |
54 ms |
7040 KB |
Output isn't correct |
49 |
Incorrect |
57 ms |
7044 KB |
Output isn't correct |
50 |
Incorrect |
178 ms |
7056 KB |
Output isn't correct |
51 |
Incorrect |
63 ms |
8280 KB |
Output isn't correct |
52 |
Incorrect |
73 ms |
8196 KB |
Output isn't correct |
53 |
Incorrect |
181 ms |
8156 KB |
Output isn't correct |
54 |
Incorrect |
77 ms |
9332 KB |
Output isn't correct |
55 |
Incorrect |
86 ms |
9424 KB |
Output isn't correct |
56 |
Incorrect |
233 ms |
9396 KB |
Output isn't correct |
57 |
Incorrect |
93 ms |
10732 KB |
Output isn't correct |
58 |
Incorrect |
100 ms |
10696 KB |
Output isn't correct |
59 |
Incorrect |
289 ms |
10664 KB |
Output isn't correct |
60 |
Incorrect |
102 ms |
12080 KB |
Output isn't correct |
61 |
Incorrect |
115 ms |
12164 KB |
Output isn't correct |
62 |
Incorrect |
290 ms |
12156 KB |
Output isn't correct |
63 |
Correct |
107 ms |
12104 KB |
Output is correct |
64 |
Incorrect |
326 ms |
12244 KB |
Output isn't correct |
65 |
Incorrect |
269 ms |
12048 KB |
Output isn't correct |
66 |
Incorrect |
104 ms |
12068 KB |
Output isn't correct |
67 |
Incorrect |
133 ms |
12120 KB |
Output isn't correct |
68 |
Correct |
140 ms |
12712 KB |
Output is correct |
69 |
Incorrect |
168 ms |
12544 KB |
Output isn't correct |
70 |
Incorrect |
139 ms |
12500 KB |
Output isn't correct |
71 |
Incorrect |
140 ms |
12492 KB |
Output isn't correct |
72 |
Incorrect |
141 ms |
12540 KB |
Output isn't correct |
73 |
Incorrect |
235 ms |
12928 KB |
Output isn't correct |
74 |
Incorrect |
238 ms |
12936 KB |
Output isn't correct |
75 |
Correct |
272 ms |
12848 KB |
Output is correct |
76 |
Incorrect |
277 ms |
12884 KB |
Output isn't correct |
77 |
Correct |
235 ms |
12916 KB |
Output is correct |
78 |
Incorrect |
595 ms |
12760 KB |
Output isn't correct |
79 |
Incorrect |
479 ms |
12756 KB |
Output isn't correct |
80 |
Incorrect |
476 ms |
12772 KB |
Output isn't correct |
81 |
Incorrect |
436 ms |
12808 KB |
Output isn't correct |
82 |
Incorrect |
502 ms |
12788 KB |
Output isn't correct |
83 |
Execution timed out |
1065 ms |
12580 KB |
Time limit exceeded |
84 |
Execution timed out |
1045 ms |
12580 KB |
Time limit exceeded |
85 |
Execution timed out |
1064 ms |
12584 KB |
Time limit exceeded |
86 |
Execution timed out |
1072 ms |
12856 KB |
Time limit exceeded |
87 |
Execution timed out |
1066 ms |
12576 KB |
Time limit exceeded |
88 |
Execution timed out |
1059 ms |
12604 KB |
Time limit exceeded |
89 |
Execution timed out |
1065 ms |
12444 KB |
Time limit exceeded |
90 |
Execution timed out |
1073 ms |
12444 KB |
Time limit exceeded |
91 |
Execution timed out |
1018 ms |
12436 KB |
Time limit exceeded |
92 |
Execution timed out |
1018 ms |
12452 KB |
Time limit exceeded |