#include "grader.h"
#include <vector>
#define pii pair<int,int>
using namespace std;
vector<pii > g[401];
int md(int r1,int c1,int r2,int c2) {
int dr = r1 - r2;
int dc = c1 - c2;
if (dr < 0) dr = -dr;
if (dc < 0) dc = -dc;
return dr + dc;
}
void Rescue(int R, int C, int RS, int CS, int X) {
int i, j;
int l = 0, r = 0;
int lb = 0, ub = 0;
for (i = 1; i <= R; ++i) {
for (j = 1; j <= C; ++j) {
int d = md(RS, CS, i, j);
if (r < d) r = d;
g[d].push_back({i,j});
}
}
while (l <= r) {
int m = (l + r) >> 1;
int RM = g[m][0].first;
int CM = g[m][0].second;
int h = Measure(RM,CM);
if (h == X) {
Pinpoint(RM,CM);
return;
}
else if (h > X) lb = m, l = m + 1;
else ub = m, r = m - 1;
}
for (i = 1; i < g[lb].size(); ++i) {
int RM = g[lb][i].first;
int CM = g[lb][i].second;
if (Measure(RM, CM) == X) {
Pinpoint(RM, CM);
return;
}
}
for (i = 1; i < g[ub].size(); ++i) {
int RM = g[ub][i].first;
int CM = g[ub][i].second;
if (Measure(RM, CM) == X) {
Pinpoint(RM, CM);
return;
}
}
}
Compilation message
mountain.cpp: In function 'void Rescue(int, int, int, int, int)':
mountain.cpp:36:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 1; i < g[lb].size(); ++i) {
~~^~~~~~~~~~~~~~
mountain.cpp:44:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 1; i < g[ub].size(); ++i) {
~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
372 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
432 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
304 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
288 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
360 KB |
Output is correct |
17 |
Correct |
5 ms |
308 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
256 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
256 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
404 KB |
Output is correct |
24 |
Correct |
5 ms |
256 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
256 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
436 KB |
Output is correct |
30 |
Correct |
5 ms |
256 KB |
Output is correct |
31 |
Correct |
5 ms |
256 KB |
Output is correct |
32 |
Correct |
4 ms |
256 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
4 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
37 |
Correct |
5 ms |
256 KB |
Output is correct |
38 |
Correct |
5 ms |
256 KB |
Output is correct |
39 |
Correct |
4 ms |
256 KB |
Output is correct |
40 |
Correct |
5 ms |
256 KB |
Output is correct |
41 |
Correct |
5 ms |
256 KB |
Output is correct |
42 |
Correct |
4 ms |
384 KB |
Output is correct |
43 |
Correct |
5 ms |
256 KB |
Output is correct |
44 |
Correct |
5 ms |
256 KB |
Output is correct |
45 |
Correct |
5 ms |
256 KB |
Output is correct |
46 |
Correct |
5 ms |
256 KB |
Output is correct |
47 |
Correct |
5 ms |
256 KB |
Output is correct |
48 |
Correct |
5 ms |
256 KB |
Output is correct |
49 |
Correct |
5 ms |
384 KB |
Output is correct |
50 |
Correct |
5 ms |
384 KB |
Output is correct |
51 |
Correct |
5 ms |
256 KB |
Output is correct |
52 |
Correct |
6 ms |
384 KB |
Output is correct |
53 |
Correct |
5 ms |
256 KB |
Output is correct |
54 |
Correct |
5 ms |
256 KB |
Output is correct |
55 |
Correct |
5 ms |
384 KB |
Output is correct |
56 |
Incorrect |
5 ms |
384 KB |
Wrong Answer [5] |
57 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
896 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |