# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
826828 |
2023-08-16T05:10:11 Z |
반딧불(#10373) |
Golf (JOI17_golf) |
C++17 |
|
3328 ms |
218148 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Rect{
int xl, yl, xr, yr;
Rect(){}
Rect(int xl, int yl, int xr, int yr): xl(xl), yl(yl), xr(xr), yr(yr){}
};
int xs, ys, xe, ye;
int n;
Rect rects[100002];
void renumber();
void solve();
int main(){
scanf("%d %d %d %d %d", &xs, &ys, &xe, &ye, &n);
for(int i=1; i<=n; i++){
scanf("%d %d %d %d", &rects[i].xl, &rects[i].xr, &rects[i].yl, &rects[i].yr);
}
renumber();
solve();
}
int H, W;
void renumber(){
vector<int> vx, vy;
vx.push_back(xs), vx.push_back(xe), vy.push_back(ys), vy.push_back(ye);
for(int i=1; i<=n; i++){
vx.push_back(rects[i].xl), vx.push_back(rects[i].xr);
vy.push_back(rects[i].yl), vy.push_back(rects[i].yr);
}
sort(vx.begin(), vx.end());
vx.erase(unique(vx.begin(), vx.end()), vx.end());
sort(vy.begin(), vy.end());
vy.erase(unique(vy.begin(), vy.end()), vy.end());
H = (int)vx.size();
W = (int)vy.size();
xs = lower_bound(vx.begin(), vx.end(), xs) - vx.begin() + 1;
xe = lower_bound(vx.begin(), vx.end(), xe) - vx.begin() + 1;
ys = lower_bound(vy.begin(), vy.end(), ys) - vy.begin() + 1;
ye = lower_bound(vy.begin(), vy.end(), ye) - vy.begin() + 1;
for(int i=1; i<=n; i++){
rects[i].xl = lower_bound(vx.begin(), vx.end(), rects[i].xl) - vx.begin() + 1;
rects[i].xr = lower_bound(vx.begin(), vx.end(), rects[i].xr) - vx.begin() + 1;
rects[i].yl = lower_bound(vy.begin(), vy.end(), rects[i].yl) - vy.begin() + 1;
rects[i].yr = lower_bound(vy.begin(), vy.end(), rects[i].yr) - vy.begin() + 1;
}
}
struct dat{
int x, y, dir, dist;
dat(){}
dat(int x, int y, int dir, int dist): x(x), y(y), dir(dir), dist(dist){}
};
const int xx[]={0, 1, 0, -1}, yy[]={1, 0, -1, 0};
deque<dat> dq;
bool visited[2102][2102][4];
int dist[2102][2102][4];
bool passable[2102][2102][4];
void solve(){
for(int i=1; i<=H; i++) for(int j=1; j<=W; j++) for(int d=0; d<4; d++) passable[i][j][d] = 1;
for(int i=1; i<=n; i++){
int xl = rects[i].xl, xr = rects[i].xr, yl = rects[i].yl, yr = rects[i].yr;
for(int x=xl+1; x<xr; x++) for(int y=yl; y<yr; y++) passable[x][y][0] = false;
for(int x=xl; x<xr; x++) for(int y=yl+1; y<yr; y++) passable[x][y][1] = false;
for(int x=xl+1; x<xr; x++) for(int y=yl+1; y<=yr; y++) passable[x][y][2] = false;
for(int x=xl+1; x<=xr; x++) for(int y=yl+1; y<yr; y++) passable[x][y][3] = false;
}
for(int i=0; i<4; i++) dq.push_back(dat(xs, ys, i, 1));
while(!dq.empty()){
dat tmp = dq.front(); dq.pop_front();
if(visited[tmp.x][tmp.y][tmp.dir]) continue;
visited[tmp.x][tmp.y][tmp.dir] = 1;
dist[tmp.x][tmp.y][tmp.dir] = tmp.dist;
//printf("%d %d %d: %d\n", tmp.x, tmp.y, tmp.dir, tmp.dist);
if(tmp.x == xe && tmp.y == ye){
printf("%d", tmp.dist);
exit(0);
}
for(int d=0; d<4; d++){
int tx = tmp.x + xx[d], ty = tmp.y + yy[d];
if(tx<1 || tx>H || ty<1 || ty>W || !passable[tmp.x][tmp.y][d]) continue;
if(d == tmp.dir) dq.push_front(dat(tx, ty, d, tmp.dist));
else dq.push_back(dat(tx, ty, d, tmp.dist+1));
}
}
exit(1);
}
Compilation message
golf.cpp: In function 'int main()':
golf.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d %d %d %d %d", &xs, &ys, &xe, &ye, &n);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
golf.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%d %d %d %d", &rects[i].xl, &rects[i].xr, &rects[i].yl, &rects[i].yr);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
3028 KB |
Output is correct |
5 |
Correct |
49 ms |
37256 KB |
Output is correct |
6 |
Correct |
33 ms |
31208 KB |
Output is correct |
7 |
Correct |
48 ms |
32708 KB |
Output is correct |
8 |
Correct |
52 ms |
34872 KB |
Output is correct |
9 |
Correct |
50 ms |
31824 KB |
Output is correct |
10 |
Correct |
24 ms |
23768 KB |
Output is correct |
11 |
Correct |
28 ms |
30756 KB |
Output is correct |
12 |
Correct |
19 ms |
20000 KB |
Output is correct |
13 |
Correct |
57 ms |
33348 KB |
Output is correct |
14 |
Correct |
44 ms |
32776 KB |
Output is correct |
15 |
Correct |
21 ms |
9300 KB |
Output is correct |
16 |
Correct |
85 ms |
25624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
3028 KB |
Output is correct |
5 |
Correct |
49 ms |
37256 KB |
Output is correct |
6 |
Correct |
33 ms |
31208 KB |
Output is correct |
7 |
Correct |
48 ms |
32708 KB |
Output is correct |
8 |
Correct |
52 ms |
34872 KB |
Output is correct |
9 |
Correct |
50 ms |
31824 KB |
Output is correct |
10 |
Correct |
24 ms |
23768 KB |
Output is correct |
11 |
Correct |
28 ms |
30756 KB |
Output is correct |
12 |
Correct |
19 ms |
20000 KB |
Output is correct |
13 |
Correct |
57 ms |
33348 KB |
Output is correct |
14 |
Correct |
44 ms |
32776 KB |
Output is correct |
15 |
Correct |
21 ms |
9300 KB |
Output is correct |
16 |
Correct |
85 ms |
25624 KB |
Output is correct |
17 |
Correct |
242 ms |
144600 KB |
Output is correct |
18 |
Correct |
227 ms |
151776 KB |
Output is correct |
19 |
Correct |
197 ms |
112212 KB |
Output is correct |
20 |
Correct |
268 ms |
147800 KB |
Output is correct |
21 |
Correct |
252 ms |
160952 KB |
Output is correct |
22 |
Correct |
133 ms |
112372 KB |
Output is correct |
23 |
Correct |
107 ms |
84184 KB |
Output is correct |
24 |
Correct |
320 ms |
139092 KB |
Output is correct |
25 |
Correct |
69 ms |
66608 KB |
Output is correct |
26 |
Correct |
250 ms |
128000 KB |
Output is correct |
27 |
Correct |
35 ms |
11980 KB |
Output is correct |
28 |
Correct |
105 ms |
29740 KB |
Output is correct |
29 |
Correct |
111 ms |
30420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
3028 KB |
Output is correct |
5 |
Correct |
49 ms |
37256 KB |
Output is correct |
6 |
Correct |
33 ms |
31208 KB |
Output is correct |
7 |
Correct |
48 ms |
32708 KB |
Output is correct |
8 |
Correct |
52 ms |
34872 KB |
Output is correct |
9 |
Correct |
50 ms |
31824 KB |
Output is correct |
10 |
Correct |
24 ms |
23768 KB |
Output is correct |
11 |
Correct |
28 ms |
30756 KB |
Output is correct |
12 |
Correct |
19 ms |
20000 KB |
Output is correct |
13 |
Correct |
57 ms |
33348 KB |
Output is correct |
14 |
Correct |
44 ms |
32776 KB |
Output is correct |
15 |
Correct |
21 ms |
9300 KB |
Output is correct |
16 |
Correct |
85 ms |
25624 KB |
Output is correct |
17 |
Correct |
242 ms |
144600 KB |
Output is correct |
18 |
Correct |
227 ms |
151776 KB |
Output is correct |
19 |
Correct |
197 ms |
112212 KB |
Output is correct |
20 |
Correct |
268 ms |
147800 KB |
Output is correct |
21 |
Correct |
252 ms |
160952 KB |
Output is correct |
22 |
Correct |
133 ms |
112372 KB |
Output is correct |
23 |
Correct |
107 ms |
84184 KB |
Output is correct |
24 |
Correct |
320 ms |
139092 KB |
Output is correct |
25 |
Correct |
69 ms |
66608 KB |
Output is correct |
26 |
Correct |
250 ms |
128000 KB |
Output is correct |
27 |
Correct |
35 ms |
11980 KB |
Output is correct |
28 |
Correct |
105 ms |
29740 KB |
Output is correct |
29 |
Correct |
111 ms |
30420 KB |
Output is correct |
30 |
Runtime error |
3328 ms |
218148 KB |
Execution killed with signal 11 |
31 |
Halted |
0 ms |
0 KB |
- |