# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
53514 |
2018-06-30T06:49:48 Z |
!?!?(#2015) |
Mecho (IOI09_mecho) |
C++11 |
|
270 ms |
6760 KB |
#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int N, S;
char arr[1024][1024];
int dist[1024][1024];
bool vis[1024][1024];
bool valid(int x, int y)
{
return 0<=x&&x<N&&0<=y&&y<N;
}
bool can(int t)
{
queue<tuple<int, int, int> > Q;
memset(vis, false, sizeof(vis));
for(int i=0; i<N; ++i)
for(int j=0; j<N; ++j)
if(arr[i][j] == 'M')
Q.emplace(t*S, i, j);
while(!Q.empty())
{
int di, x, y; tie(di, x, y) = Q.front(); Q.pop();
if(arr[x][y] == 'D') return true;
for(int d=0; d<4; ++d)
{
int nx = x+"1210"[d]-'1';
int ny = y+"0121"[d]-'1';
if(!valid(nx, ny)) continue;
if(arr[nx][ny] != 'G' && arr[nx][ny] != 'D') continue;
if(dist[nx][ny] <= di+1) continue;
if(vis[nx][ny]) continue;
Q.emplace(di+1, nx, ny);
vis[nx][ny] = true;
}
}
return false;
}
void init()
{
memset(dist, 0x3f, sizeof dist);
queue<pair<int, int> > Q;
for(int i=0; i<N; ++i)
for(int j=0; j<N; ++j)
{
if(arr[i][j] == 'H')
{
Q.emplace(i, j);
dist[i][j] = 0;
}
}
while(!Q.empty())
{
int x, y; tie(x, y) = Q.front(); Q.pop();
for(int d=0;d<4;++d)
{
int nx = x+"1210"[d] - '1';
int ny = y+"0121"[d] - '1';
if(!valid(nx, ny)) continue;
if(arr[nx][ny] != 'G') continue;
if(dist[nx][ny] != INF) continue;
dist[nx][ny] = dist[x][y]+S;
Q.emplace(nx, ny);
}
}
}
int main()
{
scanf("%d%d", &N, &S);
for(int i=0; i<N; ++i)
scanf("%s", arr[i]);
int lo = -1; //pos
int hi = N*N; //impos
init();
while(lo+1!=hi)
{
int mi = (lo+hi)/2;
if(can(mi)) lo = mi;
else hi = mi;
}
printf("%d\n", lo);
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:68: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:70:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", arr[i]);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5368 KB |
Output is correct |
2 |
Correct |
6 ms |
5476 KB |
Output is correct |
3 |
Correct |
6 ms |
5552 KB |
Output is correct |
4 |
Correct |
6 ms |
5552 KB |
Output is correct |
5 |
Correct |
6 ms |
5568 KB |
Output is correct |
6 |
Correct |
6 ms |
5568 KB |
Output is correct |
7 |
Correct |
206 ms |
6484 KB |
Output is correct |
8 |
Correct |
6 ms |
6484 KB |
Output is correct |
9 |
Correct |
7 ms |
6484 KB |
Output is correct |
10 |
Correct |
6 ms |
6484 KB |
Output is correct |
11 |
Correct |
7 ms |
6484 KB |
Output is correct |
12 |
Incorrect |
7 ms |
6484 KB |
Output isn't correct |
13 |
Incorrect |
7 ms |
6484 KB |
Output isn't correct |
14 |
Correct |
7 ms |
6484 KB |
Output is correct |
15 |
Correct |
7 ms |
6484 KB |
Output is correct |
16 |
Correct |
7 ms |
6484 KB |
Output is correct |
17 |
Correct |
6 ms |
6484 KB |
Output is correct |
18 |
Correct |
7 ms |
6484 KB |
Output is correct |
19 |
Correct |
6 ms |
6484 KB |
Output is correct |
20 |
Correct |
8 ms |
6484 KB |
Output is correct |
21 |
Correct |
6 ms |
6484 KB |
Output is correct |
22 |
Correct |
6 ms |
6484 KB |
Output is correct |
23 |
Correct |
6 ms |
6484 KB |
Output is correct |
24 |
Correct |
6 ms |
6484 KB |
Output is correct |
25 |
Correct |
7 ms |
6484 KB |
Output is correct |
26 |
Correct |
9 ms |
6484 KB |
Output is correct |
27 |
Correct |
8 ms |
6484 KB |
Output is correct |
28 |
Correct |
9 ms |
6484 KB |
Output is correct |
29 |
Correct |
8 ms |
6484 KB |
Output is correct |
30 |
Correct |
6 ms |
6484 KB |
Output is correct |
31 |
Correct |
7 ms |
6484 KB |
Output is correct |
32 |
Correct |
8 ms |
6484 KB |
Output is correct |
33 |
Correct |
14 ms |
6484 KB |
Output is correct |
34 |
Correct |
16 ms |
6484 KB |
Output is correct |
35 |
Correct |
36 ms |
6484 KB |
Output is correct |
36 |
Correct |
17 ms |
6484 KB |
Output is correct |
37 |
Correct |
18 ms |
6484 KB |
Output is correct |
38 |
Correct |
60 ms |
6484 KB |
Output is correct |
39 |
Correct |
21 ms |
6484 KB |
Output is correct |
40 |
Correct |
21 ms |
6484 KB |
Output is correct |
41 |
Correct |
57 ms |
6484 KB |
Output is correct |
42 |
Correct |
24 ms |
6484 KB |
Output is correct |
43 |
Correct |
30 ms |
6484 KB |
Output is correct |
44 |
Correct |
74 ms |
6484 KB |
Output is correct |
45 |
Correct |
28 ms |
6484 KB |
Output is correct |
46 |
Correct |
28 ms |
6484 KB |
Output is correct |
47 |
Correct |
84 ms |
6484 KB |
Output is correct |
48 |
Correct |
31 ms |
6484 KB |
Output is correct |
49 |
Correct |
31 ms |
6484 KB |
Output is correct |
50 |
Correct |
102 ms |
6484 KB |
Output is correct |
51 |
Correct |
37 ms |
6484 KB |
Output is correct |
52 |
Correct |
36 ms |
6484 KB |
Output is correct |
53 |
Correct |
166 ms |
6524 KB |
Output is correct |
54 |
Correct |
41 ms |
6524 KB |
Output is correct |
55 |
Correct |
41 ms |
6524 KB |
Output is correct |
56 |
Correct |
156 ms |
6524 KB |
Output is correct |
57 |
Correct |
46 ms |
6524 KB |
Output is correct |
58 |
Correct |
46 ms |
6524 KB |
Output is correct |
59 |
Correct |
191 ms |
6644 KB |
Output is correct |
60 |
Correct |
53 ms |
6644 KB |
Output is correct |
61 |
Correct |
51 ms |
6644 KB |
Output is correct |
62 |
Correct |
202 ms |
6644 KB |
Output is correct |
63 |
Correct |
156 ms |
6644 KB |
Output is correct |
64 |
Correct |
270 ms |
6644 KB |
Output is correct |
65 |
Correct |
213 ms |
6644 KB |
Output is correct |
66 |
Correct |
182 ms |
6644 KB |
Output is correct |
67 |
Correct |
175 ms |
6644 KB |
Output is correct |
68 |
Correct |
110 ms |
6656 KB |
Output is correct |
69 |
Correct |
118 ms |
6656 KB |
Output is correct |
70 |
Correct |
76 ms |
6656 KB |
Output is correct |
71 |
Correct |
85 ms |
6656 KB |
Output is correct |
72 |
Incorrect |
75 ms |
6656 KB |
Output isn't correct |
73 |
Incorrect |
130 ms |
6656 KB |
Output isn't correct |
74 |
Correct |
108 ms |
6656 KB |
Output is correct |
75 |
Correct |
127 ms |
6656 KB |
Output is correct |
76 |
Correct |
118 ms |
6684 KB |
Output is correct |
77 |
Correct |
141 ms |
6684 KB |
Output is correct |
78 |
Correct |
130 ms |
6684 KB |
Output is correct |
79 |
Correct |
111 ms |
6684 KB |
Output is correct |
80 |
Correct |
108 ms |
6760 KB |
Output is correct |
81 |
Correct |
144 ms |
6760 KB |
Output is correct |
82 |
Correct |
111 ms |
6760 KB |
Output is correct |
83 |
Correct |
147 ms |
6760 KB |
Output is correct |
84 |
Correct |
126 ms |
6760 KB |
Output is correct |
85 |
Correct |
173 ms |
6760 KB |
Output is correct |
86 |
Correct |
137 ms |
6760 KB |
Output is correct |
87 |
Correct |
141 ms |
6760 KB |
Output is correct |
88 |
Correct |
147 ms |
6760 KB |
Output is correct |
89 |
Correct |
170 ms |
6760 KB |
Output is correct |
90 |
Correct |
193 ms |
6760 KB |
Output is correct |
91 |
Correct |
171 ms |
6760 KB |
Output is correct |
92 |
Correct |
179 ms |
6760 KB |
Output is correct |