# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
53519 |
2018-06-30T06:54:31 Z |
!?!?(#2015) |
Mecho (IOI09_mecho) |
C++11 |
|
315 ms |
6692 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')
{
if(dist[i][j] <= t*S) return false;
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' && arr[nx][ny] != 'M') 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:71: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:73:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", arr[i]);
~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5496 KB |
Output is correct |
2 |
Correct |
6 ms |
5496 KB |
Output is correct |
3 |
Correct |
6 ms |
5532 KB |
Output is correct |
4 |
Correct |
6 ms |
5548 KB |
Output is correct |
5 |
Correct |
6 ms |
5608 KB |
Output is correct |
6 |
Correct |
6 ms |
5608 KB |
Output is correct |
7 |
Correct |
132 ms |
6520 KB |
Output is correct |
8 |
Correct |
5 ms |
6520 KB |
Output is correct |
9 |
Correct |
6 ms |
6520 KB |
Output is correct |
10 |
Correct |
7 ms |
6520 KB |
Output is correct |
11 |
Correct |
6 ms |
6520 KB |
Output is correct |
12 |
Correct |
6 ms |
6520 KB |
Output is correct |
13 |
Correct |
7 ms |
6520 KB |
Output is correct |
14 |
Correct |
7 ms |
6520 KB |
Output is correct |
15 |
Correct |
6 ms |
6520 KB |
Output is correct |
16 |
Correct |
6 ms |
6520 KB |
Output is correct |
17 |
Correct |
7 ms |
6520 KB |
Output is correct |
18 |
Correct |
6 ms |
6520 KB |
Output is correct |
19 |
Correct |
7 ms |
6520 KB |
Output is correct |
20 |
Correct |
6 ms |
6520 KB |
Output is correct |
21 |
Correct |
6 ms |
6520 KB |
Output is correct |
22 |
Correct |
7 ms |
6520 KB |
Output is correct |
23 |
Correct |
7 ms |
6520 KB |
Output is correct |
24 |
Correct |
6 ms |
6520 KB |
Output is correct |
25 |
Correct |
7 ms |
6520 KB |
Output is correct |
26 |
Correct |
7 ms |
6520 KB |
Output is correct |
27 |
Correct |
7 ms |
6520 KB |
Output is correct |
28 |
Correct |
7 ms |
6520 KB |
Output is correct |
29 |
Correct |
7 ms |
6520 KB |
Output is correct |
30 |
Correct |
7 ms |
6520 KB |
Output is correct |
31 |
Correct |
7 ms |
6520 KB |
Output is correct |
32 |
Correct |
6 ms |
6520 KB |
Output is correct |
33 |
Correct |
13 ms |
6520 KB |
Output is correct |
34 |
Correct |
16 ms |
6520 KB |
Output is correct |
35 |
Correct |
36 ms |
6520 KB |
Output is correct |
36 |
Correct |
16 ms |
6520 KB |
Output is correct |
37 |
Correct |
18 ms |
6520 KB |
Output is correct |
38 |
Correct |
48 ms |
6520 KB |
Output is correct |
39 |
Correct |
18 ms |
6520 KB |
Output is correct |
40 |
Correct |
21 ms |
6520 KB |
Output is correct |
41 |
Correct |
55 ms |
6520 KB |
Output is correct |
42 |
Correct |
20 ms |
6520 KB |
Output is correct |
43 |
Correct |
24 ms |
6520 KB |
Output is correct |
44 |
Correct |
77 ms |
6520 KB |
Output is correct |
45 |
Correct |
26 ms |
6520 KB |
Output is correct |
46 |
Correct |
28 ms |
6520 KB |
Output is correct |
47 |
Correct |
84 ms |
6520 KB |
Output is correct |
48 |
Correct |
30 ms |
6520 KB |
Output is correct |
49 |
Correct |
34 ms |
6520 KB |
Output is correct |
50 |
Correct |
97 ms |
6520 KB |
Output is correct |
51 |
Correct |
31 ms |
6520 KB |
Output is correct |
52 |
Correct |
38 ms |
6520 KB |
Output is correct |
53 |
Correct |
121 ms |
6520 KB |
Output is correct |
54 |
Correct |
38 ms |
6520 KB |
Output is correct |
55 |
Correct |
46 ms |
6520 KB |
Output is correct |
56 |
Correct |
151 ms |
6520 KB |
Output is correct |
57 |
Correct |
42 ms |
6520 KB |
Output is correct |
58 |
Correct |
56 ms |
6520 KB |
Output is correct |
59 |
Correct |
173 ms |
6520 KB |
Output is correct |
60 |
Correct |
44 ms |
6524 KB |
Output is correct |
61 |
Correct |
59 ms |
6524 KB |
Output is correct |
62 |
Correct |
204 ms |
6692 KB |
Output is correct |
63 |
Correct |
184 ms |
6692 KB |
Output is correct |
64 |
Correct |
315 ms |
6692 KB |
Output is correct |
65 |
Correct |
237 ms |
6692 KB |
Output is correct |
66 |
Correct |
200 ms |
6692 KB |
Output is correct |
67 |
Correct |
198 ms |
6692 KB |
Output is correct |
68 |
Correct |
94 ms |
6692 KB |
Output is correct |
69 |
Correct |
94 ms |
6692 KB |
Output is correct |
70 |
Correct |
77 ms |
6692 KB |
Output is correct |
71 |
Correct |
85 ms |
6692 KB |
Output is correct |
72 |
Correct |
68 ms |
6692 KB |
Output is correct |
73 |
Correct |
47 ms |
6692 KB |
Output is correct |
74 |
Correct |
101 ms |
6692 KB |
Output is correct |
75 |
Correct |
159 ms |
6692 KB |
Output is correct |
76 |
Correct |
104 ms |
6692 KB |
Output is correct |
77 |
Correct |
102 ms |
6692 KB |
Output is correct |
78 |
Correct |
136 ms |
6692 KB |
Output is correct |
79 |
Correct |
103 ms |
6692 KB |
Output is correct |
80 |
Correct |
110 ms |
6692 KB |
Output is correct |
81 |
Correct |
124 ms |
6692 KB |
Output is correct |
82 |
Correct |
109 ms |
6692 KB |
Output is correct |
83 |
Correct |
126 ms |
6692 KB |
Output is correct |
84 |
Correct |
111 ms |
6692 KB |
Output is correct |
85 |
Correct |
125 ms |
6692 KB |
Output is correct |
86 |
Correct |
118 ms |
6692 KB |
Output is correct |
87 |
Correct |
117 ms |
6692 KB |
Output is correct |
88 |
Correct |
118 ms |
6692 KB |
Output is correct |
89 |
Correct |
119 ms |
6692 KB |
Output is correct |
90 |
Correct |
130 ms |
6692 KB |
Output is correct |
91 |
Correct |
127 ms |
6692 KB |
Output is correct |
92 |
Correct |
135 ms |
6692 KB |
Output is correct |