# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
557310 |
2022-05-05T06:09:36 Z |
krit3379 |
Mecho (IOI09_mecho) |
C++17 |
|
196 ms |
9164 KB |
#include<bits/stdc++.h>
using namespace std;
#define N 805
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
struct A{
int x,y,w,cnt;
};
int dis[N][N],di[4]={1,-1,0,0},dj[4]={0,0,1,-1},ans=-1;
int n,step,sx,sy,ex,ey;
char s[N];
pair<int,int> dp[N][N];
vector<pair<int,int>> hive;
bitset<N> tree[N],vis[N];
queue<A> q;
bool sol(int mid){
int i,j,k;
for(i=1;i<=n;i++){
vis[i]=0;
for(j=1;j<=n;j++)dp[i][j]={1e9,1e9};
}
q.push({sx,sy,step,mid});
while(!q.empty()){
auto [x,y,w,cnt]=q.front();
q.pop();
if(vis[x][y])continue;
vis[x][y]=true;
for(k=0;k<4;k++){
int xx=x+di[k],yy=y+dj[k];
if(xx>0&&xx<=n&&yy>0&&yy<=n&&!vis[xx][yy]&&!tree[xx][yy]){
if(w==step&&dis[xx][yy]>=cnt+1&&make_pair(cnt+1,1)<dp[xx][yy])q.push({xx,yy,1,cnt+1}),dp[xx][yy]=make_pair(cnt+1,1);
if(w<step&&dis[xx][yy]>=cnt&&make_pair(cnt,1)<dp[xx][yy])q.push({xx,yy,w+1,cnt}),dp[xx][yy]=make_pair(cnt,w+1);
}
}
}
return vis[ex][ey];
}
int main(){
int i,j,k,l,r,mid;
scanf("%d %d",&n,&step);
for(i=1;i<=n;i++){
scanf(" %s",s+1);
for(j=1;j<=n;j++){
if(s[j]=='T')tree[i][j]=true;
else if(s[j]=='M')sx=i,sy=j;
else if(s[j]=='D')ex=i,ey=j;
else if(s[j]=='H')hive.push_back({i,j});
dis[i][j]=1e9;
}
}
for(auto [x,y]:hive)q.push({x,y,0});
while(!q.empty()){
auto [x,y,w,cnt]=q.front();
q.pop();
if(vis[x][y])continue;
vis[x][y]=true;
dis[x][y]=w;
for(k=0;k<4;k++){
int xx=x+di[k],yy=y+dj[k];
if(xx>0&&xx<=n&&yy>0&&yy<=n&&!vis[xx][yy]&&!tree[xx][yy]&&(xx!=ex||yy!=ey))q.push({xx,yy,w+1});
}
}
l=0,r=dis[sx][sy];
while(l<=r){
mid=(l+r)/2;
if(sol(mid))ans=mid,l=mid+1;
else r=mid-1;
}
printf("%d",ans);
return 0;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d %d",&n,&step);
| ~~~~~^~~~~~~~~~~~~~~~~~
mecho.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf(" %s",s+1);
| ~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
133 ms |
8524 KB |
Output is correct |
8 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
24 |
Correct |
1 ms |
720 KB |
Output is correct |
25 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
30 |
Correct |
1 ms |
852 KB |
Output is correct |
31 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
32 |
Correct |
1 ms |
852 KB |
Output is correct |
33 |
Incorrect |
7 ms |
3668 KB |
Output isn't correct |
34 |
Correct |
7 ms |
3668 KB |
Output is correct |
35 |
Correct |
29 ms |
3668 KB |
Output is correct |
36 |
Incorrect |
11 ms |
4180 KB |
Output isn't correct |
37 |
Correct |
9 ms |
4180 KB |
Output is correct |
38 |
Correct |
42 ms |
4184 KB |
Output is correct |
39 |
Incorrect |
11 ms |
4640 KB |
Output isn't correct |
40 |
Correct |
11 ms |
4680 KB |
Output is correct |
41 |
Correct |
52 ms |
4672 KB |
Output is correct |
42 |
Incorrect |
13 ms |
5116 KB |
Output isn't correct |
43 |
Correct |
14 ms |
5048 KB |
Output is correct |
44 |
Correct |
63 ms |
5076 KB |
Output is correct |
45 |
Incorrect |
15 ms |
5588 KB |
Output isn't correct |
46 |
Correct |
17 ms |
5624 KB |
Output is correct |
47 |
Correct |
80 ms |
5640 KB |
Output is correct |
48 |
Incorrect |
17 ms |
6008 KB |
Output isn't correct |
49 |
Correct |
19 ms |
6128 KB |
Output is correct |
50 |
Correct |
93 ms |
6068 KB |
Output is correct |
51 |
Incorrect |
20 ms |
6600 KB |
Output isn't correct |
52 |
Correct |
21 ms |
6484 KB |
Output is correct |
53 |
Correct |
106 ms |
6580 KB |
Output is correct |
54 |
Incorrect |
23 ms |
7000 KB |
Output isn't correct |
55 |
Correct |
26 ms |
7012 KB |
Output is correct |
56 |
Correct |
126 ms |
7092 KB |
Output is correct |
57 |
Incorrect |
27 ms |
7508 KB |
Output isn't correct |
58 |
Correct |
29 ms |
7552 KB |
Output is correct |
59 |
Correct |
143 ms |
7572 KB |
Output is correct |
60 |
Incorrect |
31 ms |
7968 KB |
Output isn't correct |
61 |
Correct |
32 ms |
7932 KB |
Output is correct |
62 |
Correct |
182 ms |
8020 KB |
Output is correct |
63 |
Correct |
119 ms |
8032 KB |
Output is correct |
64 |
Correct |
196 ms |
8028 KB |
Output is correct |
65 |
Correct |
191 ms |
8036 KB |
Output is correct |
66 |
Incorrect |
142 ms |
8032 KB |
Output isn't correct |
67 |
Correct |
128 ms |
8032 KB |
Output is correct |
68 |
Correct |
50 ms |
8012 KB |
Output is correct |
69 |
Correct |
44 ms |
8088 KB |
Output is correct |
70 |
Correct |
40 ms |
8020 KB |
Output is correct |
71 |
Correct |
31 ms |
8052 KB |
Output is correct |
72 |
Incorrect |
32 ms |
8048 KB |
Output isn't correct |
73 |
Incorrect |
51 ms |
9128 KB |
Output isn't correct |
74 |
Correct |
89 ms |
9108 KB |
Output is correct |
75 |
Correct |
90 ms |
9164 KB |
Output is correct |
76 |
Correct |
88 ms |
9036 KB |
Output is correct |
77 |
Correct |
98 ms |
8908 KB |
Output is correct |
78 |
Correct |
104 ms |
8996 KB |
Output is correct |
79 |
Correct |
83 ms |
9048 KB |
Output is correct |
80 |
Correct |
100 ms |
8940 KB |
Output is correct |
81 |
Correct |
99 ms |
9036 KB |
Output is correct |
82 |
Correct |
89 ms |
8972 KB |
Output is correct |
83 |
Correct |
123 ms |
8784 KB |
Output is correct |
84 |
Correct |
101 ms |
8872 KB |
Output is correct |
85 |
Correct |
103 ms |
8780 KB |
Output is correct |
86 |
Correct |
115 ms |
8884 KB |
Output is correct |
87 |
Correct |
104 ms |
8880 KB |
Output is correct |
88 |
Correct |
123 ms |
8624 KB |
Output is correct |
89 |
Correct |
122 ms |
8660 KB |
Output is correct |
90 |
Correct |
129 ms |
8680 KB |
Output is correct |
91 |
Correct |
135 ms |
8620 KB |
Output is correct |
92 |
Correct |
122 ms |
8688 KB |
Output is correct |