# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
742733 |
2023-05-16T20:14:38 Z |
CSQ31 |
Mecho (IOI09_mecho) |
C++17 |
|
128 ms |
7656 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] = 1;
while(!q.empty()){
pii v = q.front();
q.pop();
int k = dist[v.fi][v.se]/s;
if(dist[v.fi][v.se]%s == 0)k--;
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){
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 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
7 |
Incorrect |
82 ms |
7500 KB |
Output isn't correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
852 KB |
Output is correct |
15 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
29 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
30 |
Incorrect |
2 ms |
852 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
33 |
Incorrect |
5 ms |
3412 KB |
Output isn't correct |
34 |
Incorrect |
6 ms |
3412 KB |
Output isn't correct |
35 |
Correct |
21 ms |
3420 KB |
Output is correct |
36 |
Incorrect |
7 ms |
3828 KB |
Output isn't correct |
37 |
Incorrect |
9 ms |
3856 KB |
Output isn't correct |
38 |
Correct |
27 ms |
3796 KB |
Output is correct |
39 |
Incorrect |
8 ms |
4208 KB |
Output isn't correct |
40 |
Incorrect |
9 ms |
4180 KB |
Output isn't correct |
41 |
Correct |
35 ms |
4288 KB |
Output is correct |
42 |
Incorrect |
10 ms |
4700 KB |
Output isn't correct |
43 |
Incorrect |
10 ms |
4692 KB |
Output isn't correct |
44 |
Correct |
38 ms |
4728 KB |
Output is correct |
45 |
Incorrect |
11 ms |
5076 KB |
Output isn't correct |
46 |
Incorrect |
13 ms |
5188 KB |
Output isn't correct |
47 |
Correct |
46 ms |
5160 KB |
Output is correct |
48 |
Incorrect |
14 ms |
5580 KB |
Output isn't correct |
49 |
Incorrect |
15 ms |
5628 KB |
Output isn't correct |
50 |
Correct |
57 ms |
5620 KB |
Output is correct |
51 |
Incorrect |
16 ms |
5948 KB |
Output isn't correct |
52 |
Incorrect |
18 ms |
5972 KB |
Output isn't correct |
53 |
Correct |
67 ms |
6052 KB |
Output is correct |
54 |
Incorrect |
17 ms |
6440 KB |
Output isn't correct |
55 |
Incorrect |
25 ms |
6452 KB |
Output isn't correct |
56 |
Correct |
90 ms |
6488 KB |
Output is correct |
57 |
Incorrect |
19 ms |
6948 KB |
Output isn't correct |
58 |
Incorrect |
22 ms |
6860 KB |
Output isn't correct |
59 |
Correct |
87 ms |
6828 KB |
Output is correct |
60 |
Incorrect |
22 ms |
7372 KB |
Output isn't correct |
61 |
Incorrect |
25 ms |
7304 KB |
Output isn't correct |
62 |
Correct |
100 ms |
7284 KB |
Output is correct |
63 |
Incorrect |
20 ms |
7372 KB |
Output isn't correct |
64 |
Incorrect |
128 ms |
7364 KB |
Output isn't correct |
65 |
Incorrect |
33 ms |
7240 KB |
Output isn't correct |
66 |
Incorrect |
20 ms |
7284 KB |
Output isn't correct |
67 |
Correct |
21 ms |
7296 KB |
Output is correct |
68 |
Incorrect |
24 ms |
7508 KB |
Output isn't correct |
69 |
Incorrect |
36 ms |
7480 KB |
Output isn't correct |
70 |
Incorrect |
22 ms |
7472 KB |
Output isn't correct |
71 |
Incorrect |
24 ms |
7464 KB |
Output isn't correct |
72 |
Incorrect |
27 ms |
7496 KB |
Output isn't correct |
73 |
Correct |
34 ms |
7600 KB |
Output is correct |
74 |
Correct |
70 ms |
7648 KB |
Output is correct |
75 |
Correct |
77 ms |
7636 KB |
Output is correct |
76 |
Correct |
57 ms |
7604 KB |
Output is correct |
77 |
Correct |
56 ms |
7656 KB |
Output is correct |
78 |
Correct |
26 ms |
7516 KB |
Output is correct |
79 |
Correct |
53 ms |
7612 KB |
Output is correct |
80 |
Correct |
56 ms |
7624 KB |
Output is correct |
81 |
Correct |
60 ms |
7612 KB |
Output is correct |
82 |
Correct |
53 ms |
7620 KB |
Output is correct |
83 |
Correct |
67 ms |
7572 KB |
Output is correct |
84 |
Correct |
67 ms |
7572 KB |
Output is correct |
85 |
Correct |
67 ms |
7652 KB |
Output is correct |
86 |
Correct |
65 ms |
7520 KB |
Output is correct |
87 |
Correct |
66 ms |
7628 KB |
Output is correct |
88 |
Correct |
65 ms |
7508 KB |
Output is correct |
89 |
Correct |
71 ms |
7532 KB |
Output is correct |
90 |
Correct |
66 ms |
7500 KB |
Output is correct |
91 |
Correct |
69 ms |
7508 KB |
Output is correct |
92 |
Correct |
74 ms |
7528 KB |
Output is correct |