# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
742736 |
2023-05-16T20:19:21 Z |
CSQ31 |
Mecho (IOI09_mecho) |
C++17 |
|
168 ms |
7676 KB |
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int n,s,dx[4] = {0,0,1,-1},dy[4] = {1,-1,0,0};
int dist[1000][1000],bdist[1000][1000];
char grid[1000][1000];
pii st,ed;
bool check(int tim){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
dist[i][j] = 1e9;
}
}
queue<pii>q;
q.push(st);
dist[st.fi][st.se] = 0;
while(!q.empty()){
pii v = q.front();
q.pop();
int d = dist[v.fi][v.se];
int k = d/s;
if(k+tim >= bdist[v.fi][v.se]){
dist[v.fi][v.se] = 1e9;
continue;
}
for(int i=0;i<4;i++){
int x = v.fi+dx[i];
int y = v.se+dy[i];
if(x>=0 && x<n && y>=0 && y<n && grid[x][y] != 'H' && grid[x][y] != 'T' && dist[x][y] ==1e9){
dist[x][y] = dist[v.fi][v.se]+1;
q.push({x,y});
}
}
}
return dist[ed.fi][ed.se] != 1e9;
}
int main()
{
owo
cin>>n>>s;
queue<pii>bee;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>grid[i][j];
bdist[i][j] = 1e9;
if(grid[i][j] == 'M')st = {i,j};
if(grid[i][j] == 'D')ed = {i,j};
if(grid[i][j] == 'H'){
bdist[i][j] = 0;
bee.push({i,j});
}
}
}
while(!bee.empty()){
pii v = bee.front();
bee.pop();
for(int i=0;i<4;i++){
int x = v.fi+dx[i];
int y = v.se+dy[i];
if(x>=0 && x<n && y>=0 && y<n && bdist[x][y] == 1e9 && grid[x][y] == 'G'){
bdist[x][y] = bdist[v.fi][v.se] +1;
bee.push({x,y});
}
}
}
if(!check(0)){
cout<<-1;
return 0;
}
int l = 0,r = n*n;
while(r>=l){
int mid = (l+r)/2;
if(check(mid))l = mid+1;
else r = mid-1;
}
cout<<r<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
284 KB |
Output is correct |
6 |
Correct |
0 ms |
464 KB |
Output is correct |
7 |
Correct |
70 ms |
7484 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
14 |
Correct |
1 ms |
852 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
21 |
Correct |
0 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
724 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
1 ms |
852 KB |
Output is correct |
26 |
Correct |
1 ms |
852 KB |
Output is correct |
27 |
Correct |
1 ms |
852 KB |
Output is correct |
28 |
Correct |
1 ms |
852 KB |
Output is correct |
29 |
Correct |
1 ms |
852 KB |
Output is correct |
30 |
Correct |
1 ms |
852 KB |
Output is correct |
31 |
Correct |
1 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
5 ms |
3412 KB |
Output is correct |
34 |
Correct |
6 ms |
3412 KB |
Output is correct |
35 |
Correct |
18 ms |
3412 KB |
Output is correct |
36 |
Correct |
6 ms |
3796 KB |
Output is correct |
37 |
Correct |
7 ms |
3796 KB |
Output is correct |
38 |
Correct |
23 ms |
3864 KB |
Output is correct |
39 |
Correct |
8 ms |
4180 KB |
Output is correct |
40 |
Correct |
10 ms |
4180 KB |
Output is correct |
41 |
Correct |
31 ms |
4180 KB |
Output is correct |
42 |
Correct |
9 ms |
4644 KB |
Output is correct |
43 |
Correct |
14 ms |
4696 KB |
Output is correct |
44 |
Correct |
40 ms |
4728 KB |
Output is correct |
45 |
Correct |
12 ms |
5064 KB |
Output is correct |
46 |
Correct |
17 ms |
5076 KB |
Output is correct |
47 |
Correct |
44 ms |
5100 KB |
Output is correct |
48 |
Correct |
12 ms |
5588 KB |
Output is correct |
49 |
Correct |
15 ms |
5588 KB |
Output is correct |
50 |
Correct |
52 ms |
5608 KB |
Output is correct |
51 |
Correct |
14 ms |
5972 KB |
Output is correct |
52 |
Correct |
18 ms |
5972 KB |
Output is correct |
53 |
Correct |
81 ms |
6048 KB |
Output is correct |
54 |
Correct |
16 ms |
6500 KB |
Output is correct |
55 |
Correct |
25 ms |
6508 KB |
Output is correct |
56 |
Correct |
76 ms |
6484 KB |
Output is correct |
57 |
Correct |
20 ms |
6868 KB |
Output is correct |
58 |
Correct |
24 ms |
6868 KB |
Output is correct |
59 |
Correct |
87 ms |
6924 KB |
Output is correct |
60 |
Correct |
20 ms |
7376 KB |
Output is correct |
61 |
Correct |
26 ms |
7364 KB |
Output is correct |
62 |
Correct |
106 ms |
7380 KB |
Output is correct |
63 |
Correct |
100 ms |
7360 KB |
Output is correct |
64 |
Correct |
168 ms |
7360 KB |
Output is correct |
65 |
Correct |
155 ms |
7320 KB |
Output is correct |
66 |
Correct |
111 ms |
7444 KB |
Output is correct |
67 |
Correct |
31 ms |
7292 KB |
Output is correct |
68 |
Correct |
46 ms |
7372 KB |
Output is correct |
69 |
Correct |
44 ms |
7392 KB |
Output is correct |
70 |
Correct |
32 ms |
7296 KB |
Output is correct |
71 |
Correct |
37 ms |
7348 KB |
Output is correct |
72 |
Incorrect |
34 ms |
7388 KB |
Output isn't correct |
73 |
Incorrect |
59 ms |
7596 KB |
Output isn't correct |
74 |
Correct |
60 ms |
7640 KB |
Output is correct |
75 |
Correct |
60 ms |
7596 KB |
Output is correct |
76 |
Correct |
60 ms |
7644 KB |
Output is correct |
77 |
Correct |
55 ms |
7624 KB |
Output is correct |
78 |
Correct |
27 ms |
7636 KB |
Output is correct |
79 |
Correct |
53 ms |
7532 KB |
Output is correct |
80 |
Correct |
49 ms |
7620 KB |
Output is correct |
81 |
Correct |
58 ms |
7616 KB |
Output is correct |
82 |
Correct |
55 ms |
7676 KB |
Output is correct |
83 |
Correct |
64 ms |
7532 KB |
Output is correct |
84 |
Correct |
62 ms |
7508 KB |
Output is correct |
85 |
Correct |
65 ms |
7580 KB |
Output is correct |
86 |
Correct |
67 ms |
7572 KB |
Output is correct |
87 |
Correct |
71 ms |
7576 KB |
Output is correct |
88 |
Correct |
69 ms |
7520 KB |
Output is correct |
89 |
Correct |
73 ms |
7480 KB |
Output is correct |
90 |
Correct |
69 ms |
7488 KB |
Output is correct |
91 |
Correct |
70 ms |
7524 KB |
Output is correct |
92 |
Correct |
74 ms |
7524 KB |
Output is correct |