# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
122752 |
2019-06-29T08:33:41 Z |
김세빈(#2998) |
Golf (JOI17_golf) |
C++14 |
|
3307 ms |
39800 KB |
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
queue <pii> Q;
vector <int> X, Y;
int S[2020][2020], K[2020][2020];
int A[1010], B[1010], C[1010], D[1010];
bool chk[2020][2020];
int n, x, y, sx, sy, ex, ey;
int main()
{
int i, j, p, d, px, py;
scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
X.push_back(sx); X.push_back(ex);
Y.push_back(sy); Y.push_back(ey);
scanf("%d", &n);
for(i=0; i<n; i++){
scanf("%d%d%d%d", A + i, B + i, C + i, D + i);
X.push_back(A[i]); X.push_back(B[i]);
Y.push_back(C[i]); Y.push_back(D[i]);
}
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());
sort(Y.begin(), Y.end());
Y.erase(unique(Y.begin(), Y.end()), Y.end());
x = X.size(); y = Y.size();
sx = lower_bound(X.begin(), X.end(), sx) - X.begin();
sy = lower_bound(Y.begin(), Y.end(), sy) - Y.begin();
ex = lower_bound(X.begin(), X.end(), ex) - X.begin();
ey = lower_bound(Y.begin(), Y.end(), ey) - Y.begin();
for(i=0; i<n; i++){
A[i] = lower_bound(X.begin(), X.end(), A[i]) - X.begin();
B[i] = lower_bound(X.begin(), X.end(), B[i]) - X.begin();
C[i] = lower_bound(Y.begin(), Y.end(), C[i]) - Y.begin();
D[i] = lower_bound(Y.begin(), Y.end(), D[i]) - Y.begin();
S[A[i]][C[i]] ++; S[B[i]][D[i]] ++;
S[A[i]][D[i]] --; S[B[i]][C[i]] --;
}
for(i=0; i<x; i++){
for(j=0; j<y; j++){
if(i) S[i][j] += S[i - 1][j];
if(j) S[i][j] += S[i][j - 1];
if(i && j) S[i][j] -= S[i - 1][j - 1];
K[i][j] = 1e9;
}
}
chk[sx][sy] = 1; K[sx][sy] = 0;
Q.push(pii(sx * y + sy, 0));
for(; !Q.empty(); ){
tie(p, d) = Q.front(); Q.pop();
px = p / y; py = p % y; K[px][py] = d;
if(px == ex && py == ey){
printf("%d\n", d);
return 0;
}
for(i=1; px+i<x; i++){
if((py && S[px + i - 1][py] && S[px + i - 1][py - 1]) || K[px + i][py] <= d) break;
if(chk[px + i][py]) continue;
chk[px + i][py] = 1; Q.push(pii((px + i) * y + py, d + 1));
}
for(i=1; px-i>=0; i++){
if((py && S[px - i][py] && S[px - i][py - 1]) || K[px - i][py] <= d) break;
if(chk[px - i][py]) continue;
chk[px - i][py] = 1; Q.push(pii((px - i) * y + py, d + 1));
}
for(i=1; py+i<y; i++){
if((px && S[px][py + i - 1] && S[px - 1][py + i - 1]) || K[px][py + i] <= d) break;
if(chk[px][py + i]) continue;
chk[px][py + i] = 1; Q.push(pii(px * y + (py + i), d + 1));
}
for(i=1; py-i>=0; i++){
if((px && S[px][py - i] && S[px - 1][py - i]) || K[px][py - i] <= d) break;
if(chk[px][py - i]) continue;
chk[px][py - i] = 1; Q.push(pii(px * y + (py - i), d + 1));
}
}
return 0;
}
Compilation message
golf.cpp: In function 'int main()':
golf.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
golf.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
golf.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", A + i, B + i, C + i, D + i);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
2432 KB |
Output is correct |
5 |
Correct |
87 ms |
13456 KB |
Output is correct |
6 |
Correct |
85 ms |
14200 KB |
Output is correct |
7 |
Correct |
113 ms |
13896 KB |
Output is correct |
8 |
Correct |
68 ms |
14560 KB |
Output is correct |
9 |
Correct |
72 ms |
13312 KB |
Output is correct |
10 |
Correct |
52 ms |
14560 KB |
Output is correct |
11 |
Correct |
54 ms |
14968 KB |
Output is correct |
12 |
Correct |
53 ms |
14200 KB |
Output is correct |
13 |
Correct |
80 ms |
14072 KB |
Output is correct |
14 |
Correct |
63 ms |
14584 KB |
Output is correct |
15 |
Correct |
72 ms |
5760 KB |
Output is correct |
16 |
Correct |
1126 ms |
13684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
2432 KB |
Output is correct |
5 |
Correct |
87 ms |
13456 KB |
Output is correct |
6 |
Correct |
85 ms |
14200 KB |
Output is correct |
7 |
Correct |
113 ms |
13896 KB |
Output is correct |
8 |
Correct |
68 ms |
14560 KB |
Output is correct |
9 |
Correct |
72 ms |
13312 KB |
Output is correct |
10 |
Correct |
52 ms |
14560 KB |
Output is correct |
11 |
Correct |
54 ms |
14968 KB |
Output is correct |
12 |
Correct |
53 ms |
14200 KB |
Output is correct |
13 |
Correct |
80 ms |
14072 KB |
Output is correct |
14 |
Correct |
63 ms |
14584 KB |
Output is correct |
15 |
Correct |
72 ms |
5760 KB |
Output is correct |
16 |
Correct |
1126 ms |
13684 KB |
Output is correct |
17 |
Correct |
1970 ms |
39120 KB |
Output is correct |
18 |
Correct |
3307 ms |
39236 KB |
Output is correct |
19 |
Correct |
422 ms |
37740 KB |
Output is correct |
20 |
Correct |
1849 ms |
38856 KB |
Output is correct |
21 |
Correct |
1179 ms |
39800 KB |
Output is correct |
22 |
Correct |
645 ms |
39140 KB |
Output is correct |
23 |
Correct |
890 ms |
38648 KB |
Output is correct |
24 |
Correct |
1129 ms |
38396 KB |
Output is correct |
25 |
Correct |
235 ms |
37592 KB |
Output is correct |
26 |
Correct |
1499 ms |
38440 KB |
Output is correct |
27 |
Correct |
109 ms |
7040 KB |
Output is correct |
28 |
Correct |
1531 ms |
15412 KB |
Output is correct |
29 |
Correct |
1794 ms |
15744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
2432 KB |
Output is correct |
5 |
Correct |
87 ms |
13456 KB |
Output is correct |
6 |
Correct |
85 ms |
14200 KB |
Output is correct |
7 |
Correct |
113 ms |
13896 KB |
Output is correct |
8 |
Correct |
68 ms |
14560 KB |
Output is correct |
9 |
Correct |
72 ms |
13312 KB |
Output is correct |
10 |
Correct |
52 ms |
14560 KB |
Output is correct |
11 |
Correct |
54 ms |
14968 KB |
Output is correct |
12 |
Correct |
53 ms |
14200 KB |
Output is correct |
13 |
Correct |
80 ms |
14072 KB |
Output is correct |
14 |
Correct |
63 ms |
14584 KB |
Output is correct |
15 |
Correct |
72 ms |
5760 KB |
Output is correct |
16 |
Correct |
1126 ms |
13684 KB |
Output is correct |
17 |
Correct |
1970 ms |
39120 KB |
Output is correct |
18 |
Correct |
3307 ms |
39236 KB |
Output is correct |
19 |
Correct |
422 ms |
37740 KB |
Output is correct |
20 |
Correct |
1849 ms |
38856 KB |
Output is correct |
21 |
Correct |
1179 ms |
39800 KB |
Output is correct |
22 |
Correct |
645 ms |
39140 KB |
Output is correct |
23 |
Correct |
890 ms |
38648 KB |
Output is correct |
24 |
Correct |
1129 ms |
38396 KB |
Output is correct |
25 |
Correct |
235 ms |
37592 KB |
Output is correct |
26 |
Correct |
1499 ms |
38440 KB |
Output is correct |
27 |
Correct |
109 ms |
7040 KB |
Output is correct |
28 |
Correct |
1531 ms |
15412 KB |
Output is correct |
29 |
Correct |
1794 ms |
15744 KB |
Output is correct |
30 |
Runtime error |
105 ms |
4724 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
31 |
Halted |
0 ms |
0 KB |
- |