# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
122756 |
2019-06-29T08:43:26 Z |
임유진(#2862) |
Golf (JOI17_golf) |
C++14 |
|
56 ms |
1024 KB |
#include<stdio.h>
#include<vector>
#include<queue>
using namespace std;
#define MAXN 1005
typedef pair<int, bool> pib;
const int INF=1e9+5;
int S, T, U, V, N;
int A[MAXN], B[MAXN], C[MAXN], D[MAXN];
int x1[2*MAXN], x2[2*MAXN], y[2*MAXN], x[2*MAXN], y1[2*MAXN], y2[2*MAXN];
void hor(int idx, int x) {
x1[idx] = 0;
x2[idx] = INF;
for(int i = 0; i < N; i++) if(C[i] < y[idx] && y[idx] < D[i]) {
if(B[i] <= x) x1[idx] = max(x1[idx], B[i]);
else x2[idx] = min(x2[idx], A[i]);
}
}
void ver(int idx, int y) {
y1[idx] = 0;
y2[idx] = INF;
for(int i = 0; i < N; i++) if(A[i] < x[idx] && x[idx] < B[i]) {
if(D[i] <= y) y1[idx] = max(y1[idx], D[i]);
else y2[idx] = min(y2[idx], C[i]);
}
}
int main(){
vector<int> e[4*MAXN];
queue<int> q;
int dp[4*MAXN];
//freopen("input.txt", "r", stdin);
scanf("%d%d%d%d%d", &S, &T, &U, &V, &N);
for(int i=0; i<N; i++) scanf("%d%d%d%d", A+i, B+i, C+i, D+i);
for(int i=0; i<N; i++) {
y[i*2] = C[i];
hor(i*2, A[i]);
y[i*2+1] = D[i];
hor(i*2+1, A[i]);
x[i*2] = A[i];
ver(i*2, C[i]);
x[i*2+1] = B[i];
ver(i*2+1, C[i]);
}
y[N*2] = T;
hor(N*2, S);
x[N*2] = S;
ver(N*2, T);
y[N*2+1] = V;
hor(N*2+1, U);
x[N*2+1] = U;
ver(N*2+1, V);
if(S == U && y1[2*N] <= V && V <= y2[2*N+1]) {
printf("1");
return 0;
}
if(T == V && x1[2*N] <= U && U <= x2[2*N+1]) {
printf("1");
return 0;
}
for(int i = 0; i < 2*N+2; i++) for(int j = 0; j < 2*N+2; j++)
if(x1[i] <= x[j] && x[j] <= x2[i] && y1[j] <= y[i] && y[i] <= y2[j]) {
e[i].push_back(2*N+2+j);
e[2*N+2+j].push_back(i);
}
dp[2*N] = dp[4*N+2] = 1;
q.push(2*N);
q.push(4*N+2);
while(!q.empty()) {
int t = q.front();
q.pop();
for(auto a : e[t]) if(dp[a] == 0) {
dp[a] = dp[t] + 1;
q.push(a);
}
}
printf("%d", min(dp[2*N+1], dp[4*N+3]));
return 0;
}
Compilation message
golf.cpp: In function 'int main()':
golf.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d%d", &S, &T, &U, &V, &N);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
golf.cpp:42: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("%d%d%d%d", A+i, B+i, C+i, D+i);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
512 KB |
Output is correct |
5 |
Correct |
35 ms |
1016 KB |
Output is correct |
6 |
Correct |
47 ms |
1016 KB |
Output is correct |
7 |
Correct |
37 ms |
1024 KB |
Output is correct |
8 |
Correct |
36 ms |
1024 KB |
Output is correct |
9 |
Correct |
38 ms |
1016 KB |
Output is correct |
10 |
Correct |
40 ms |
1016 KB |
Output is correct |
11 |
Correct |
37 ms |
1016 KB |
Output is correct |
12 |
Correct |
37 ms |
1024 KB |
Output is correct |
13 |
Correct |
46 ms |
1016 KB |
Output is correct |
14 |
Correct |
37 ms |
1024 KB |
Output is correct |
15 |
Correct |
7 ms |
640 KB |
Output is correct |
16 |
Correct |
14 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
512 KB |
Output is correct |
5 |
Correct |
35 ms |
1016 KB |
Output is correct |
6 |
Correct |
47 ms |
1016 KB |
Output is correct |
7 |
Correct |
37 ms |
1024 KB |
Output is correct |
8 |
Correct |
36 ms |
1024 KB |
Output is correct |
9 |
Correct |
38 ms |
1016 KB |
Output is correct |
10 |
Correct |
40 ms |
1016 KB |
Output is correct |
11 |
Correct |
37 ms |
1016 KB |
Output is correct |
12 |
Correct |
37 ms |
1024 KB |
Output is correct |
13 |
Correct |
46 ms |
1016 KB |
Output is correct |
14 |
Correct |
37 ms |
1024 KB |
Output is correct |
15 |
Correct |
7 ms |
640 KB |
Output is correct |
16 |
Correct |
14 ms |
768 KB |
Output is correct |
17 |
Correct |
37 ms |
872 KB |
Output is correct |
18 |
Correct |
37 ms |
888 KB |
Output is correct |
19 |
Correct |
36 ms |
888 KB |
Output is correct |
20 |
Correct |
37 ms |
888 KB |
Output is correct |
21 |
Correct |
56 ms |
888 KB |
Output is correct |
22 |
Correct |
53 ms |
888 KB |
Output is correct |
23 |
Correct |
37 ms |
888 KB |
Output is correct |
24 |
Correct |
37 ms |
888 KB |
Output is correct |
25 |
Correct |
44 ms |
912 KB |
Output is correct |
26 |
Correct |
39 ms |
864 KB |
Output is correct |
27 |
Correct |
8 ms |
640 KB |
Output is correct |
28 |
Correct |
16 ms |
768 KB |
Output is correct |
29 |
Correct |
16 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
512 KB |
Output is correct |
5 |
Correct |
35 ms |
1016 KB |
Output is correct |
6 |
Correct |
47 ms |
1016 KB |
Output is correct |
7 |
Correct |
37 ms |
1024 KB |
Output is correct |
8 |
Correct |
36 ms |
1024 KB |
Output is correct |
9 |
Correct |
38 ms |
1016 KB |
Output is correct |
10 |
Correct |
40 ms |
1016 KB |
Output is correct |
11 |
Correct |
37 ms |
1016 KB |
Output is correct |
12 |
Correct |
37 ms |
1024 KB |
Output is correct |
13 |
Correct |
46 ms |
1016 KB |
Output is correct |
14 |
Correct |
37 ms |
1024 KB |
Output is correct |
15 |
Correct |
7 ms |
640 KB |
Output is correct |
16 |
Correct |
14 ms |
768 KB |
Output is correct |
17 |
Correct |
37 ms |
872 KB |
Output is correct |
18 |
Correct |
37 ms |
888 KB |
Output is correct |
19 |
Correct |
36 ms |
888 KB |
Output is correct |
20 |
Correct |
37 ms |
888 KB |
Output is correct |
21 |
Correct |
56 ms |
888 KB |
Output is correct |
22 |
Correct |
53 ms |
888 KB |
Output is correct |
23 |
Correct |
37 ms |
888 KB |
Output is correct |
24 |
Correct |
37 ms |
888 KB |
Output is correct |
25 |
Correct |
44 ms |
912 KB |
Output is correct |
26 |
Correct |
39 ms |
864 KB |
Output is correct |
27 |
Correct |
8 ms |
640 KB |
Output is correct |
28 |
Correct |
16 ms |
768 KB |
Output is correct |
29 |
Correct |
16 ms |
768 KB |
Output is correct |
30 |
Execution timed out |
6 ms |
384 KB |
Time limit exceeded (wall clock) |
31 |
Halted |
0 ms |
0 KB |
- |