# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
54434 |
2018-07-03T12:17:56 Z |
upsolving(#1416) |
Mecho (IOI09_mecho) |
C++11 |
|
243 ms |
22088 KB |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
int pre[2000][2000];
char mark[2000][2000];
int homex,homey;
int s,sx,sy,N;
bool test(int time)
{
bool reach[2005][2005];
memset(reach,0,sizeof(reach));
if(time * s >= pre[homex][homey]) return false;
queue<piii> q;
q.push(make_pair(make_pair(sx,sy),time*s));
reach[sx][sy]=1;
while(!q.empty())
{
int x=q.front().first.first;
int y=q.front().first.second;
int dis=q.front().second;
if(mark[x][y]=='D') return true;
q.pop();
for(int c=0;c<4;c++)
{
int cx=x+dx[c],cy=y+dy[c];
if(cx<0 || cx>=N || cy<0 || cy>=N || pre[cx][cy]<=dis+1 || mark[cx][cy]=='T' || reach[cx][cy]) continue;
reach[cx][cy]=true;
q.push(make_pair(make_pair(cx,cy),dis+1));
}
}
return false;
}
int main()
{
memset(pre,-1,sizeof(pre));
scanf("%d %d",&N,&s);
queue<pii> que;
for(int i=0;i<N;i++)scanf("%s",mark[i]);
for(int i=0;i<N;i++){
for(int j=0;j<N;j++)
{
if(mark[i][j]=='M') sx=i,sy=j,mark[i][j]='G';
if(mark[i][j]=='D') homex=i,homey=j;
if(mark[i][j]=='H') que.push(make_pair(i,j)),pre[i][j]=0;
}
}
pre[homex][homey]=N*N*s;
while(!que.empty())
{
int x=que.front().first;
int y=que.front().second;
int dis=pre[x][y];
que.pop();
for(int c=0;c<4;c++)
{
int cx=x+dx[c],cy=y+dy[c];
if(cx<0 || cx>=N || cy<0 || cy>=N || pre[cx][cy]!=-1 || mark[cx][cy]!='G') continue;
pre[cx][cy]=dis+s;
que.push(make_pair(cx,cy));
}
}
int low=0,high=N*N*2,ans=-1;
for(;low<high;)
{
int mid=(low+high)/2;
if(test(mid)) ans=max(ans,mid),low=mid+1;
else high=mid;
}
return !printf("%d",ans);
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&N,&s);
~~~~~^~~~~~~~~~~~~~~
mecho.cpp:40:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=0;i<N;i++)scanf("%s",mark[i]);
~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
19836 KB |
Output is correct |
2 |
Correct |
17 ms |
20104 KB |
Output is correct |
3 |
Correct |
16 ms |
20104 KB |
Output is correct |
4 |
Correct |
17 ms |
20104 KB |
Output is correct |
5 |
Correct |
17 ms |
20104 KB |
Output is correct |
6 |
Correct |
18 ms |
20104 KB |
Output is correct |
7 |
Correct |
127 ms |
21760 KB |
Output is correct |
8 |
Correct |
18 ms |
21760 KB |
Output is correct |
9 |
Correct |
18 ms |
21760 KB |
Output is correct |
10 |
Correct |
20 ms |
21760 KB |
Output is correct |
11 |
Correct |
17 ms |
21760 KB |
Output is correct |
12 |
Incorrect |
19 ms |
21760 KB |
Output isn't correct |
13 |
Incorrect |
20 ms |
21760 KB |
Output isn't correct |
14 |
Correct |
19 ms |
21760 KB |
Output is correct |
15 |
Correct |
20 ms |
21760 KB |
Output is correct |
16 |
Correct |
18 ms |
21760 KB |
Output is correct |
17 |
Correct |
18 ms |
21760 KB |
Output is correct |
18 |
Correct |
18 ms |
21760 KB |
Output is correct |
19 |
Correct |
18 ms |
21760 KB |
Output is correct |
20 |
Correct |
18 ms |
21760 KB |
Output is correct |
21 |
Correct |
18 ms |
21760 KB |
Output is correct |
22 |
Correct |
18 ms |
21760 KB |
Output is correct |
23 |
Correct |
20 ms |
21760 KB |
Output is correct |
24 |
Correct |
20 ms |
21760 KB |
Output is correct |
25 |
Correct |
18 ms |
21760 KB |
Output is correct |
26 |
Correct |
19 ms |
21760 KB |
Output is correct |
27 |
Correct |
19 ms |
21760 KB |
Output is correct |
28 |
Correct |
18 ms |
21760 KB |
Output is correct |
29 |
Correct |
19 ms |
21760 KB |
Output is correct |
30 |
Correct |
19 ms |
21760 KB |
Output is correct |
31 |
Correct |
18 ms |
21760 KB |
Output is correct |
32 |
Correct |
19 ms |
21760 KB |
Output is correct |
33 |
Correct |
25 ms |
21760 KB |
Output is correct |
34 |
Correct |
22 ms |
21760 KB |
Output is correct |
35 |
Correct |
43 ms |
21760 KB |
Output is correct |
36 |
Correct |
23 ms |
21760 KB |
Output is correct |
37 |
Correct |
24 ms |
21760 KB |
Output is correct |
38 |
Correct |
60 ms |
21760 KB |
Output is correct |
39 |
Correct |
28 ms |
21760 KB |
Output is correct |
40 |
Correct |
24 ms |
21760 KB |
Output is correct |
41 |
Correct |
77 ms |
21760 KB |
Output is correct |
42 |
Correct |
33 ms |
21760 KB |
Output is correct |
43 |
Correct |
37 ms |
21760 KB |
Output is correct |
44 |
Correct |
112 ms |
21760 KB |
Output is correct |
45 |
Correct |
36 ms |
21760 KB |
Output is correct |
46 |
Correct |
34 ms |
21760 KB |
Output is correct |
47 |
Correct |
138 ms |
21760 KB |
Output is correct |
48 |
Correct |
31 ms |
21760 KB |
Output is correct |
49 |
Correct |
28 ms |
21760 KB |
Output is correct |
50 |
Correct |
127 ms |
21760 KB |
Output is correct |
51 |
Correct |
39 ms |
21760 KB |
Output is correct |
52 |
Correct |
30 ms |
21760 KB |
Output is correct |
53 |
Correct |
141 ms |
21760 KB |
Output is correct |
54 |
Correct |
41 ms |
21760 KB |
Output is correct |
55 |
Correct |
30 ms |
21760 KB |
Output is correct |
56 |
Correct |
168 ms |
21760 KB |
Output is correct |
57 |
Correct |
32 ms |
21760 KB |
Output is correct |
58 |
Correct |
33 ms |
21760 KB |
Output is correct |
59 |
Correct |
188 ms |
21760 KB |
Output is correct |
60 |
Correct |
33 ms |
21760 KB |
Output is correct |
61 |
Correct |
33 ms |
21760 KB |
Output is correct |
62 |
Correct |
235 ms |
21828 KB |
Output is correct |
63 |
Correct |
175 ms |
21900 KB |
Output is correct |
64 |
Correct |
243 ms |
21900 KB |
Output is correct |
65 |
Correct |
236 ms |
21900 KB |
Output is correct |
66 |
Correct |
169 ms |
21900 KB |
Output is correct |
67 |
Correct |
186 ms |
21900 KB |
Output is correct |
68 |
Correct |
92 ms |
21900 KB |
Output is correct |
69 |
Correct |
63 ms |
21900 KB |
Output is correct |
70 |
Correct |
61 ms |
21900 KB |
Output is correct |
71 |
Correct |
54 ms |
21900 KB |
Output is correct |
72 |
Incorrect |
51 ms |
21900 KB |
Output isn't correct |
73 |
Incorrect |
66 ms |
21956 KB |
Output isn't correct |
74 |
Correct |
78 ms |
22012 KB |
Output is correct |
75 |
Correct |
92 ms |
22088 KB |
Output is correct |
76 |
Correct |
103 ms |
22088 KB |
Output is correct |
77 |
Correct |
98 ms |
22088 KB |
Output is correct |
78 |
Correct |
160 ms |
22088 KB |
Output is correct |
79 |
Correct |
66 ms |
22088 KB |
Output is correct |
80 |
Correct |
82 ms |
22088 KB |
Output is correct |
81 |
Correct |
101 ms |
22088 KB |
Output is correct |
82 |
Correct |
90 ms |
22088 KB |
Output is correct |
83 |
Correct |
139 ms |
22088 KB |
Output is correct |
84 |
Correct |
124 ms |
22088 KB |
Output is correct |
85 |
Correct |
122 ms |
22088 KB |
Output is correct |
86 |
Correct |
115 ms |
22088 KB |
Output is correct |
87 |
Correct |
101 ms |
22088 KB |
Output is correct |
88 |
Correct |
117 ms |
22088 KB |
Output is correct |
89 |
Correct |
111 ms |
22088 KB |
Output is correct |
90 |
Correct |
112 ms |
22088 KB |
Output is correct |
91 |
Correct |
123 ms |
22088 KB |
Output is correct |
92 |
Correct |
111 ms |
22088 KB |
Output is correct |