# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
787413 |
2023-07-19T07:01:56 Z |
박상훈(#10032) |
Hamburg Steak (JOI20_hamburg) |
C++17 |
|
3000 ms |
36056 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int INF = 1e9 + 100;
struct Rect{
int x1, y1, x2, y2;
Rect(){}
Rect(int _x1, int _y1, int _x2, int _y2): x1(_x1), y1(_y1), x2(_x2), y2(_y2) {}
void read(){
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
}
bool in(int x, int y){
return x1 <= x && x <= x2 && y1 <= y && y <= y2;
}
};
vector<pair<int, int>> ans;
void solve(vector<Rect> V, int k){
if (k==0){
if (!V.empty()) return;
for (auto &[x, y]:ans) printf("%d %d\n", x, y);
exit(0);
}
int lx = INF, rx = -INF, ly = INF, ry = -INF;
for (auto &[x1, y1, x2, y2]:V){
lx = min(lx, x2);
rx = max(rx, x1);
ly = min(ly, y2);
ry = max(ry, y1);
}
if (V.empty()) lx = rx = ly = ry = 1;
vector<pair<int, int>> C = {{lx, ly}, {lx, ry}, {rx, ly}, {rx, ry}};
if (k==4){
vector<int> Y = {-INF};
for (auto &[x1, y1, x2, y2]:V) if (x2 >= rx){
Y.push_back(y1);
Y.push_back(y2);
}
sort(Y.begin(), Y.end());
Y.erase(unique(Y.begin(), Y.end()), Y.end());
vector<int> sum(Y.size()), I(Y.size());
for (auto &[x1, y1, x2, y2]:V) if (x2 >= rx){
int i1 = lower_bound(Y.begin(), Y.end(), y1) - Y.begin();
int i2 = lower_bound(Y.begin(), Y.end(), y2) - Y.begin();
if (i2+1 < (int)sum.size()) sum[i2+1]--;
sum[i1]++;
}
for (int i=1;i<(int)sum.size();i++) sum[i] += sum[i-1], I[i] = i;
sort(I.begin()+1, I.end(), [&](int i, int j){return sum[i] > sum[j];});
for (int i0=1;i0<(int)I.size();i0++){
int y = Y[I[i0]];
C.emplace_back(rx, y);
}
// for (auto &[x1, y1, x2, y2]:V) if (x2 >= rx){
// C.emplace_back(rx, y1);
// C.emplace_back(rx, y2);
// // C.emplace_back(x2, y1);
// // C.emplace_back(x2, y2);
// }
}
for (auto &[x, y]:C){
vector<Rect> nV;
for (auto &R:V) if (!R.in(x, y)) nV.push_back(R);
ans.emplace_back(x, y);
solve(nV, k-1);
ans.pop_back();
}
}
int main(){
int n, k;
scanf("%d %d", &n, &k);
vector<Rect> V(n);
for (int i=0;i<n;i++) V[i].read();
solve(V, k);
printf("failed\n");
return 0;
}
Compilation message
hamburg.cpp: In function 'int main()':
hamburg.cpp:85:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | scanf("%d %d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~
hamburg.cpp: In member function 'void Rect::read()':
hamburg.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
584 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
224 ms |
600 KB |
Output is correct |
15 |
Correct |
3 ms |
628 KB |
Output is correct |
16 |
Correct |
3 ms |
600 KB |
Output is correct |
17 |
Correct |
4 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
624 KB |
Output is correct |
19 |
Correct |
3 ms |
620 KB |
Output is correct |
20 |
Correct |
31 ms |
600 KB |
Output is correct |
21 |
Correct |
4 ms |
636 KB |
Output is correct |
22 |
Correct |
3 ms |
612 KB |
Output is correct |
23 |
Correct |
5 ms |
636 KB |
Output is correct |
24 |
Correct |
4 ms |
596 KB |
Output is correct |
25 |
Correct |
3 ms |
596 KB |
Output is correct |
26 |
Correct |
3 ms |
596 KB |
Output is correct |
27 |
Correct |
3 ms |
596 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
41 ms |
596 KB |
Output is correct |
32 |
Correct |
3 ms |
576 KB |
Output is correct |
33 |
Correct |
3 ms |
596 KB |
Output is correct |
34 |
Correct |
23 ms |
596 KB |
Output is correct |
35 |
Correct |
4 ms |
616 KB |
Output is correct |
36 |
Correct |
5 ms |
596 KB |
Output is correct |
37 |
Correct |
5 ms |
656 KB |
Output is correct |
38 |
Correct |
6 ms |
644 KB |
Output is correct |
39 |
Correct |
8 ms |
628 KB |
Output is correct |
40 |
Correct |
224 ms |
596 KB |
Output is correct |
41 |
Correct |
10 ms |
572 KB |
Output is correct |
42 |
Correct |
5 ms |
616 KB |
Output is correct |
43 |
Correct |
4 ms |
632 KB |
Output is correct |
44 |
Correct |
5 ms |
656 KB |
Output is correct |
45 |
Correct |
2 ms |
468 KB |
Output is correct |
46 |
Correct |
5 ms |
608 KB |
Output is correct |
47 |
Correct |
316 ms |
608 KB |
Output is correct |
48 |
Correct |
7 ms |
632 KB |
Output is correct |
49 |
Correct |
4 ms |
660 KB |
Output is correct |
50 |
Correct |
51 ms |
644 KB |
Output is correct |
51 |
Correct |
4 ms |
596 KB |
Output is correct |
52 |
Correct |
133 ms |
596 KB |
Output is correct |
53 |
Correct |
5 ms |
664 KB |
Output is correct |
54 |
Correct |
5 ms |
628 KB |
Output is correct |
55 |
Correct |
3 ms |
468 KB |
Output is correct |
56 |
Correct |
3 ms |
468 KB |
Output is correct |
57 |
Correct |
3 ms |
468 KB |
Output is correct |
58 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
72 ms |
6524 KB |
Output is correct |
6 |
Correct |
73 ms |
6464 KB |
Output is correct |
7 |
Correct |
69 ms |
6512 KB |
Output is correct |
8 |
Correct |
74 ms |
6536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
72 ms |
9052 KB |
Output is correct |
6 |
Correct |
73 ms |
8796 KB |
Output is correct |
7 |
Correct |
71 ms |
8912 KB |
Output is correct |
8 |
Correct |
87 ms |
17616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
584 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
73 ms |
9900 KB |
Output is correct |
14 |
Correct |
87 ms |
10188 KB |
Output is correct |
15 |
Correct |
76 ms |
8752 KB |
Output is correct |
16 |
Correct |
75 ms |
9020 KB |
Output is correct |
17 |
Correct |
74 ms |
11376 KB |
Output is correct |
18 |
Correct |
87 ms |
8752 KB |
Output is correct |
19 |
Correct |
87 ms |
11780 KB |
Output is correct |
20 |
Correct |
79 ms |
15360 KB |
Output is correct |
21 |
Correct |
189 ms |
27184 KB |
Output is correct |
22 |
Correct |
105 ms |
18560 KB |
Output is correct |
23 |
Correct |
115 ms |
21768 KB |
Output is correct |
24 |
Correct |
114 ms |
24536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
224 ms |
600 KB |
Output is correct |
15 |
Correct |
3 ms |
628 KB |
Output is correct |
16 |
Correct |
3 ms |
600 KB |
Output is correct |
17 |
Correct |
4 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
624 KB |
Output is correct |
19 |
Correct |
3 ms |
620 KB |
Output is correct |
20 |
Correct |
31 ms |
600 KB |
Output is correct |
21 |
Correct |
4 ms |
636 KB |
Output is correct |
22 |
Correct |
3 ms |
612 KB |
Output is correct |
23 |
Correct |
5 ms |
636 KB |
Output is correct |
24 |
Correct |
4 ms |
596 KB |
Output is correct |
25 |
Correct |
3 ms |
596 KB |
Output is correct |
26 |
Correct |
3 ms |
596 KB |
Output is correct |
27 |
Correct |
3 ms |
596 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
41 ms |
596 KB |
Output is correct |
32 |
Correct |
3 ms |
576 KB |
Output is correct |
33 |
Correct |
3 ms |
596 KB |
Output is correct |
34 |
Correct |
23 ms |
596 KB |
Output is correct |
35 |
Correct |
4 ms |
616 KB |
Output is correct |
36 |
Correct |
5 ms |
596 KB |
Output is correct |
37 |
Correct |
5 ms |
656 KB |
Output is correct |
38 |
Correct |
6 ms |
644 KB |
Output is correct |
39 |
Correct |
8 ms |
628 KB |
Output is correct |
40 |
Correct |
224 ms |
596 KB |
Output is correct |
41 |
Correct |
10 ms |
572 KB |
Output is correct |
42 |
Correct |
5 ms |
616 KB |
Output is correct |
43 |
Correct |
4 ms |
632 KB |
Output is correct |
44 |
Correct |
5 ms |
656 KB |
Output is correct |
45 |
Correct |
2 ms |
468 KB |
Output is correct |
46 |
Correct |
5 ms |
608 KB |
Output is correct |
47 |
Correct |
316 ms |
608 KB |
Output is correct |
48 |
Correct |
7 ms |
632 KB |
Output is correct |
49 |
Correct |
4 ms |
660 KB |
Output is correct |
50 |
Correct |
51 ms |
644 KB |
Output is correct |
51 |
Correct |
4 ms |
596 KB |
Output is correct |
52 |
Correct |
133 ms |
596 KB |
Output is correct |
53 |
Correct |
5 ms |
664 KB |
Output is correct |
54 |
Correct |
5 ms |
628 KB |
Output is correct |
55 |
Correct |
3 ms |
468 KB |
Output is correct |
56 |
Correct |
3 ms |
468 KB |
Output is correct |
57 |
Correct |
3 ms |
468 KB |
Output is correct |
58 |
Correct |
3 ms |
468 KB |
Output is correct |
59 |
Correct |
110 ms |
14624 KB |
Output is correct |
60 |
Correct |
200 ms |
15552 KB |
Output is correct |
61 |
Correct |
111 ms |
12820 KB |
Output is correct |
62 |
Correct |
203 ms |
15424 KB |
Output is correct |
63 |
Correct |
151 ms |
14236 KB |
Output is correct |
64 |
Correct |
188 ms |
15484 KB |
Output is correct |
65 |
Correct |
158 ms |
15296 KB |
Output is correct |
66 |
Correct |
184 ms |
16180 KB |
Output is correct |
67 |
Correct |
178 ms |
28980 KB |
Output is correct |
68 |
Correct |
170 ms |
24492 KB |
Output is correct |
69 |
Correct |
130 ms |
18732 KB |
Output is correct |
70 |
Correct |
153 ms |
25040 KB |
Output is correct |
71 |
Correct |
564 ms |
34796 KB |
Output is correct |
72 |
Correct |
693 ms |
34856 KB |
Output is correct |
73 |
Correct |
461 ms |
34332 KB |
Output is correct |
74 |
Correct |
381 ms |
34072 KB |
Output is correct |
75 |
Correct |
373 ms |
33840 KB |
Output is correct |
76 |
Correct |
327 ms |
34040 KB |
Output is correct |
77 |
Correct |
369 ms |
34948 KB |
Output is correct |
78 |
Correct |
755 ms |
34180 KB |
Output is correct |
79 |
Correct |
389 ms |
34472 KB |
Output is correct |
80 |
Correct |
381 ms |
34388 KB |
Output is correct |
81 |
Correct |
714 ms |
34096 KB |
Output is correct |
82 |
Correct |
328 ms |
33608 KB |
Output is correct |
83 |
Correct |
253 ms |
32288 KB |
Output is correct |
84 |
Correct |
222 ms |
22320 KB |
Output is correct |
85 |
Correct |
329 ms |
33356 KB |
Output is correct |
86 |
Correct |
243 ms |
28740 KB |
Output is correct |
87 |
Correct |
296 ms |
32992 KB |
Output is correct |
88 |
Correct |
274 ms |
32536 KB |
Output is correct |
89 |
Correct |
428 ms |
33484 KB |
Output is correct |
90 |
Correct |
2830 ms |
34456 KB |
Output is correct |
91 |
Correct |
413 ms |
36056 KB |
Output is correct |
92 |
Correct |
659 ms |
34800 KB |
Output is correct |
93 |
Execution timed out |
3019 ms |
35156 KB |
Time limit exceeded |
94 |
Halted |
0 ms |
0 KB |
- |