# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
138757 |
2019-07-30T09:53:30 Z |
Boxworld |
Mecho (IOI09_mecho) |
C++14 |
|
1000 ms |
9336 KB |
#include <bits/stdc++.h>
using namespace std;
const int N=1010;
typedef pair<int,int> pii;
char G[N][N];
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
int T[N][N],d[N][N],vis[N][N];
int n,s,sx,sy;
int bfs(int time){
if (time*s>=T[sx][sy])return 0;
memset(vis,0,sizeof(vis));
queue<pii> Q;
vis[sx][sy]=1;
Q.push(make_pair(sx*N+sy,time*s));
while(!Q.empty()){
int dis=Q.front().second;
int x=Q.front().first/N;
int y=Q.front().first%N;
Q.pop();
if (G[x][y]=='D')return 1;
for (int k=0;k<4;k++){
int X=x+dx[k],Y=y+dy[k];
if (X<1||X>N||Y<1||Y>N)continue;
if (G[X][Y]=='T')continue;
if (dis+1>=T[X][Y]||vis[X][Y])continue;
vis[X][Y]=1;
Q.push(make_pair(X*N+Y,dis+1));
}
}
return 0;
}
int main(){
scanf("%d%d",&n,&s);
for (int i=1;i<=n;i++)scanf("%s",G[i]+1);
memset(T,-1,sizeof(T));
queue<int> bq;
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++){
if (G[i][j]=='M')sx=i,sy=j;
if (G[i][j]=='D')T[i][j]=n*n*s;
if (G[i][j]=='H'){
T[i][j]=0;
bq.push(i*N+j);
}
}
while(!bq.empty()){
int x=bq.front()/N,y=bq.front()%N;
bq.pop();
for (int i=0;i<4;i++){
int X=x+dx[i],Y=y+dy[i];
if (x<1||x>n||y<1||y>n||T[X][Y]!=-1)continue;
if (G[X][Y]=='T'||G[X][Y]=='D')continue;
T[X][Y]=T[x][y]+s;
bq.push(X*N+Y);
}
}
int l=-1,r=n*n*2;
while(l<r){
int m=(l+r)/2;
if (bfs(m))l=m;
else r=m;
}
printf("%d\n",l);
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&s);
~~~~~^~~~~~~~~~~~~~
mecho.cpp:35:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i=1;i<=n;i++)scanf("%s",G[i]+1);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1063 ms |
8312 KB |
Time limit exceeded |
2 |
Execution timed out |
1057 ms |
8312 KB |
Time limit exceeded |
3 |
Execution timed out |
1069 ms |
8312 KB |
Time limit exceeded |
4 |
Execution timed out |
1076 ms |
8312 KB |
Time limit exceeded |
5 |
Execution timed out |
1069 ms |
8312 KB |
Time limit exceeded |
6 |
Execution timed out |
1070 ms |
8312 KB |
Time limit exceeded |
7 |
Execution timed out |
1069 ms |
9208 KB |
Time limit exceeded |
8 |
Execution timed out |
1072 ms |
8312 KB |
Time limit exceeded |
9 |
Execution timed out |
1074 ms |
8312 KB |
Time limit exceeded |
10 |
Execution timed out |
1073 ms |
8312 KB |
Time limit exceeded |
11 |
Execution timed out |
1080 ms |
8312 KB |
Time limit exceeded |
12 |
Execution timed out |
1079 ms |
8312 KB |
Time limit exceeded |
13 |
Execution timed out |
1078 ms |
8312 KB |
Time limit exceeded |
14 |
Execution timed out |
1073 ms |
8440 KB |
Time limit exceeded |
15 |
Execution timed out |
1079 ms |
8312 KB |
Time limit exceeded |
16 |
Execution timed out |
1075 ms |
8312 KB |
Time limit exceeded |
17 |
Execution timed out |
1062 ms |
8312 KB |
Time limit exceeded |
18 |
Execution timed out |
1062 ms |
8312 KB |
Time limit exceeded |
19 |
Execution timed out |
1056 ms |
8312 KB |
Time limit exceeded |
20 |
Execution timed out |
1063 ms |
8312 KB |
Time limit exceeded |
21 |
Execution timed out |
1067 ms |
8312 KB |
Time limit exceeded |
22 |
Execution timed out |
1076 ms |
8312 KB |
Time limit exceeded |
23 |
Execution timed out |
1068 ms |
8312 KB |
Time limit exceeded |
24 |
Execution timed out |
1066 ms |
8440 KB |
Time limit exceeded |
25 |
Execution timed out |
1072 ms |
8440 KB |
Time limit exceeded |
26 |
Execution timed out |
1069 ms |
8412 KB |
Time limit exceeded |
27 |
Execution timed out |
1072 ms |
8312 KB |
Time limit exceeded |
28 |
Execution timed out |
1050 ms |
8440 KB |
Time limit exceeded |
29 |
Execution timed out |
1073 ms |
8312 KB |
Time limit exceeded |
30 |
Execution timed out |
1074 ms |
8316 KB |
Time limit exceeded |
31 |
Execution timed out |
1062 ms |
8440 KB |
Time limit exceeded |
32 |
Execution timed out |
1073 ms |
8312 KB |
Time limit exceeded |
33 |
Execution timed out |
1061 ms |
8696 KB |
Time limit exceeded |
34 |
Execution timed out |
1070 ms |
8696 KB |
Time limit exceeded |
35 |
Execution timed out |
1069 ms |
8696 KB |
Time limit exceeded |
36 |
Execution timed out |
1080 ms |
8696 KB |
Time limit exceeded |
37 |
Execution timed out |
1072 ms |
8696 KB |
Time limit exceeded |
38 |
Execution timed out |
1073 ms |
8696 KB |
Time limit exceeded |
39 |
Execution timed out |
1079 ms |
8824 KB |
Time limit exceeded |
40 |
Execution timed out |
1069 ms |
8804 KB |
Time limit exceeded |
41 |
Execution timed out |
1069 ms |
8696 KB |
Time limit exceeded |
42 |
Execution timed out |
1068 ms |
8824 KB |
Time limit exceeded |
43 |
Execution timed out |
1056 ms |
8824 KB |
Time limit exceeded |
44 |
Execution timed out |
1066 ms |
8824 KB |
Time limit exceeded |
45 |
Execution timed out |
1060 ms |
8824 KB |
Time limit exceeded |
46 |
Execution timed out |
1070 ms |
8824 KB |
Time limit exceeded |
47 |
Execution timed out |
1075 ms |
8824 KB |
Time limit exceeded |
48 |
Execution timed out |
1077 ms |
8824 KB |
Time limit exceeded |
49 |
Execution timed out |
1069 ms |
8824 KB |
Time limit exceeded |
50 |
Execution timed out |
1058 ms |
9080 KB |
Time limit exceeded |
51 |
Execution timed out |
1080 ms |
8952 KB |
Time limit exceeded |
52 |
Execution timed out |
1073 ms |
8824 KB |
Time limit exceeded |
53 |
Execution timed out |
1065 ms |
9080 KB |
Time limit exceeded |
54 |
Execution timed out |
1071 ms |
8952 KB |
Time limit exceeded |
55 |
Execution timed out |
1076 ms |
8952 KB |
Time limit exceeded |
56 |
Execution timed out |
1059 ms |
9080 KB |
Time limit exceeded |
57 |
Execution timed out |
1049 ms |
9044 KB |
Time limit exceeded |
58 |
Execution timed out |
1049 ms |
9080 KB |
Time limit exceeded |
59 |
Execution timed out |
1062 ms |
9080 KB |
Time limit exceeded |
60 |
Execution timed out |
1065 ms |
9080 KB |
Time limit exceeded |
61 |
Execution timed out |
1054 ms |
9080 KB |
Time limit exceeded |
62 |
Execution timed out |
1061 ms |
9208 KB |
Time limit exceeded |
63 |
Execution timed out |
1068 ms |
9080 KB |
Time limit exceeded |
64 |
Execution timed out |
1064 ms |
9120 KB |
Time limit exceeded |
65 |
Execution timed out |
1072 ms |
9080 KB |
Time limit exceeded |
66 |
Execution timed out |
1050 ms |
9080 KB |
Time limit exceeded |
67 |
Execution timed out |
1053 ms |
9080 KB |
Time limit exceeded |
68 |
Execution timed out |
1079 ms |
9180 KB |
Time limit exceeded |
69 |
Execution timed out |
1076 ms |
9080 KB |
Time limit exceeded |
70 |
Execution timed out |
1060 ms |
9080 KB |
Time limit exceeded |
71 |
Execution timed out |
1062 ms |
9136 KB |
Time limit exceeded |
72 |
Execution timed out |
1067 ms |
9080 KB |
Time limit exceeded |
73 |
Execution timed out |
1050 ms |
9208 KB |
Time limit exceeded |
74 |
Execution timed out |
1051 ms |
9208 KB |
Time limit exceeded |
75 |
Execution timed out |
1061 ms |
9256 KB |
Time limit exceeded |
76 |
Execution timed out |
1080 ms |
9208 KB |
Time limit exceeded |
77 |
Execution timed out |
1063 ms |
9208 KB |
Time limit exceeded |
78 |
Execution timed out |
1052 ms |
9336 KB |
Time limit exceeded |
79 |
Execution timed out |
1067 ms |
9208 KB |
Time limit exceeded |
80 |
Execution timed out |
1065 ms |
9252 KB |
Time limit exceeded |
81 |
Execution timed out |
1074 ms |
9208 KB |
Time limit exceeded |
82 |
Execution timed out |
1082 ms |
9208 KB |
Time limit exceeded |
83 |
Execution timed out |
1062 ms |
9208 KB |
Time limit exceeded |
84 |
Execution timed out |
1073 ms |
9208 KB |
Time limit exceeded |
85 |
Execution timed out |
1068 ms |
9208 KB |
Time limit exceeded |
86 |
Execution timed out |
1071 ms |
9208 KB |
Time limit exceeded |
87 |
Execution timed out |
1066 ms |
9224 KB |
Time limit exceeded |
88 |
Execution timed out |
1079 ms |
9208 KB |
Time limit exceeded |
89 |
Execution timed out |
1073 ms |
9208 KB |
Time limit exceeded |
90 |
Execution timed out |
1061 ms |
9208 KB |
Time limit exceeded |
91 |
Execution timed out |
1083 ms |
9208 KB |
Time limit exceeded |
92 |
Execution timed out |
1063 ms |
9208 KB |
Time limit exceeded |