답안 #648450

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648450 2022-10-06T14:02:00 Z 406 함박 스테이크 (JOI20_hamburg) C++17
21 / 100
3000 ms 32024 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

const int N = 2e5 + 50;
const int M = 2 * N + 5;
int l[N], r[N], u[N], d[N], n, k;
bitset<N> used, full;
vector<pair<int, int>> points;
vector<int> X, Y, cl[M], op[M];
int cnt;

void rec();

inline bool inter(int i, int x, int y) {
        return l[i] <= x && x <= r[i] && d[i] <= y && y <= u[i];
}

inline void add_point(int x, int y) {
        vector<int> change;
        for (int i = used._Find_first(); i < n; i = used._Find_next(i)) {
                if (inter(i, x, y)) {
                        cnt--;
                        used[i] = false;
                        change.push_back(i);
                }
        }
        if (change.empty())
                return;
        points.emplace_back(x, y);

        rec();

        for (auto cc: change) used[cc] = true, cnt++;
        points.pop_back();

}

void rec() {
        if (!cnt && points.size() <= k) {
                for (int i = 0; i < (int) points.size(); i++)
                        cout << X[points[i].first] << ' ' << Y[points[i].second] << '\n';
                for (int i = points.size(); i < k; i++)
                        cout << 1 << ' ' << 1 << '\n';
                exit(0);
        }
        if (points.size() >= k)
                return;

        int minR = 2 * n;
        int minU = 2 * n;
        int maxD = 0;
        int maxL = 0;

        for (int i = used._Find_first(); i < n; i = used._Find_next(i)) {
                minR = min(minR, r[i]);
                maxL = max(maxL, l[i]);

                minU = min(minU, u[i]);
                maxD = max(maxD, d[i]);
        }

        if (maxL <= minR || maxD <= minU) {
                add_point(minR, minU);
        }
        else {
                add_point(minR, minU);
                add_point(minR, maxD);
                add_point(maxL, minU);
                add_point(maxL, maxD);
                if (points.size())
                        return;

                int mxD = 0;
                int mnU = 2 * n;
                for (int i = 0; i < n; i++) if (l[i] <= minR) {
                        mxD = max(mxD, d[i]);
                        mnU = min(mnU, u[i]);
                }
                add_point(minR, mxD);
                add_point(minR, mnU);
                mxD = 0;
                mnU = 2 * n;
                for (int i = 0; i < n; i++) if (r[i] >= maxL) {
                        mxD = max(mxD, d[i]);
                        mnU = min(mnU, u[i]);
                }

                add_point(maxL, mxD);
                add_point(maxL, mnU);

                int mxL = 0;
                int mnR = 2 * n;

                for (int i = 0; i < n; i++) if (u[i] >= maxD) {
                        mxL = max(mxL, l[i]);
                        mnR = min(mnR, r[i]);
                }
                add_point(mxL, maxD);
                add_point(mnR, maxD);

                mxL = 0;
                mnR = 2 * n;

                for (int i = 0; i < n; i++) if (d[i] <= minU) {
                        mxL = max(mxL, l[i]);
                        mnR = min(mnR, r[i]);
                }

                add_point(mxL, minU);
                add_point(mnR, minU);

                for (int i = 0; i < n; i++) if (l[i] <= minR)
                        op[d[i]].push_back(i), cl[u[i]].push_back(i);
                for (int h = 0; h < Y.size(); h++) {
                        for (auto u: op[h]) {
                                used[u] = false;
                                cnt--;
                        }
                        if (cl[h].size()) {
                                points.emplace_back(minR, h);
                                rec();
                                points.pop_back();
                        }
                        for (auto v: cl[h]) {
                                used[v] = true;
                                cnt++;
                        }
                }
        }
}

signed main() {
        ios::sync_with_stdio(0);
        cin.tie(0);

        cin >> n >> k;
        X.reserve(2 * n), Y.reserve(2 * n);
        for (int i = 0; i < n; i++) {
                cin >> l[i] >> d[i] >> r[i] >> u[i];
                X.push_back(l[i]);
                X.push_back(r[i]);
                Y.push_back(d[i]);
                Y.push_back(u[i]);
        }
        sort(X.begin(), X.end());
        X.resize(unique(X.begin(), X.end()) - X.begin());

        sort(Y.begin(), Y.end());
        Y.resize(unique(Y.begin(), Y.end()) - Y.begin());

        for (int i = 0; i < n; i++) {
                l[i] = lower_bound(X.begin(), X.end(), l[i]) - X.begin();
                r[i] = lower_bound(X.begin(), X.end(), r[i]) - X.begin();

                u[i] = lower_bound(Y.begin(), Y.end(), u[i]) - Y.begin();
                d[i] = lower_bound(Y.begin(), Y.end(), d[i]) - Y.begin();
        }

        for (int i = 0; i < n; i++)
                used[i] = true;
        cnt = n;

        rec();
        cout << "NO I DID NOT FIND ANYTHING\n";
        return 0;
}

Compilation message

hamburg.cpp: In function 'void rec()':
hamburg.cpp:42:35: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |         if (!cnt && points.size() <= k) {
      |                     ~~~~~~~~~~~~~~^~~~
hamburg.cpp:49:27: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |         if (points.size() >= k)
      |             ~~~~~~~~~~~~~~^~~~
hamburg.cpp:117:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |                 for (int h = 0; h < Y.size(); h++) {
      |                                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19156 KB Output is correct
2 Correct 12 ms 19156 KB Output is correct
3 Correct 12 ms 19156 KB Output is correct
4 Correct 12 ms 19156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 19156 KB Output is correct
2 Correct 15 ms 19216 KB Output is correct
3 Correct 13 ms 19208 KB Output is correct
4 Correct 15 ms 19156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19220 KB Output is correct
2 Correct 13 ms 19192 KB Output is correct
3 Correct 12 ms 19204 KB Output is correct
4 Correct 12 ms 19128 KB Output is correct
5 Correct 12 ms 19164 KB Output is correct
6 Correct 12 ms 19152 KB Output is correct
7 Correct 12 ms 19156 KB Output is correct
8 Correct 12 ms 19216 KB Output is correct
9 Correct 13 ms 19156 KB Output is correct
10 Correct 13 ms 19156 KB Output is correct
11 Correct 14 ms 19156 KB Output is correct
12 Correct 12 ms 19204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 19188 KB Output is correct
2 Correct 13 ms 19200 KB Output is correct
3 Correct 13 ms 19172 KB Output is correct
4 Correct 12 ms 19156 KB Output is correct
5 Correct 12 ms 19124 KB Output is correct
6 Correct 12 ms 19208 KB Output is correct
7 Correct 13 ms 19200 KB Output is correct
8 Correct 13 ms 19156 KB Output is correct
9 Correct 13 ms 19156 KB Output is correct
10 Correct 13 ms 19156 KB Output is correct
11 Correct 13 ms 19156 KB Output is correct
12 Correct 13 ms 19156 KB Output is correct
13 Correct 16 ms 19136 KB Output is correct
14 Correct 131 ms 19288 KB Output is correct
15 Correct 15 ms 19284 KB Output is correct
16 Correct 14 ms 19312 KB Output is correct
17 Correct 51 ms 19376 KB Output is correct
18 Correct 16 ms 19284 KB Output is correct
19 Correct 13 ms 19284 KB Output is correct
20 Correct 98 ms 19308 KB Output is correct
21 Correct 15 ms 19192 KB Output is correct
22 Correct 16 ms 19284 KB Output is correct
23 Correct 27 ms 19284 KB Output is correct
24 Correct 14 ms 19296 KB Output is correct
25 Correct 15 ms 19284 KB Output is correct
26 Correct 15 ms 19244 KB Output is correct
27 Correct 15 ms 19200 KB Output is correct
28 Correct 14 ms 19404 KB Output is correct
29 Correct 14 ms 19284 KB Output is correct
30 Correct 14 ms 19284 KB Output is correct
31 Correct 33 ms 19336 KB Output is correct
32 Correct 72 ms 19372 KB Output is correct
33 Correct 43 ms 19344 KB Output is correct
34 Correct 24 ms 19296 KB Output is correct
35 Correct 23 ms 19276 KB Output is correct
36 Correct 197 ms 19376 KB Output is correct
37 Correct 19 ms 19284 KB Output is correct
38 Correct 34 ms 19236 KB Output is correct
39 Correct 130 ms 19284 KB Output is correct
40 Correct 104 ms 19284 KB Output is correct
41 Correct 27 ms 19232 KB Output is correct
42 Correct 75 ms 19436 KB Output is correct
43 Correct 157 ms 19360 KB Output is correct
44 Correct 29 ms 19420 KB Output is correct
45 Correct 17 ms 19232 KB Output is correct
46 Correct 79 ms 19348 KB Output is correct
47 Correct 43 ms 19328 KB Output is correct
48 Correct 60 ms 19236 KB Output is correct
49 Correct 38 ms 19268 KB Output is correct
50 Correct 27 ms 19304 KB Output is correct
51 Correct 75 ms 19324 KB Output is correct
52 Correct 116 ms 19356 KB Output is correct
53 Correct 30 ms 19292 KB Output is correct
54 Correct 31 ms 19308 KB Output is correct
55 Correct 22 ms 19264 KB Output is correct
56 Correct 21 ms 19272 KB Output is correct
57 Correct 17 ms 19284 KB Output is correct
58 Correct 18 ms 19284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19156 KB Output is correct
2 Correct 12 ms 19156 KB Output is correct
3 Correct 12 ms 19156 KB Output is correct
4 Correct 12 ms 19156 KB Output is correct
5 Correct 271 ms 26480 KB Output is correct
6 Correct 306 ms 26628 KB Output is correct
7 Correct 286 ms 26476 KB Output is correct
8 Correct 274 ms 26524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 19156 KB Output is correct
2 Correct 15 ms 19216 KB Output is correct
3 Correct 13 ms 19208 KB Output is correct
4 Correct 15 ms 19156 KB Output is correct
5 Correct 274 ms 26628 KB Output is correct
6 Correct 309 ms 26916 KB Output is correct
7 Correct 267 ms 26568 KB Output is correct
8 Correct 315 ms 26772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19220 KB Output is correct
2 Correct 13 ms 19192 KB Output is correct
3 Correct 12 ms 19204 KB Output is correct
4 Correct 12 ms 19128 KB Output is correct
5 Correct 12 ms 19164 KB Output is correct
6 Correct 12 ms 19152 KB Output is correct
7 Correct 12 ms 19156 KB Output is correct
8 Correct 12 ms 19216 KB Output is correct
9 Correct 13 ms 19156 KB Output is correct
10 Correct 13 ms 19156 KB Output is correct
11 Correct 14 ms 19156 KB Output is correct
12 Correct 12 ms 19204 KB Output is correct
13 Correct 275 ms 26544 KB Output is correct
14 Correct 291 ms 26284 KB Output is correct
15 Correct 270 ms 26488 KB Output is correct
16 Correct 263 ms 26444 KB Output is correct
17 Correct 268 ms 26420 KB Output is correct
18 Correct 274 ms 26556 KB Output is correct
19 Correct 265 ms 26408 KB Output is correct
20 Correct 285 ms 26424 KB Output is correct
21 Correct 391 ms 26696 KB Output is correct
22 Correct 311 ms 26448 KB Output is correct
23 Correct 311 ms 26600 KB Output is correct
24 Correct 324 ms 26588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 19188 KB Output is correct
2 Correct 13 ms 19200 KB Output is correct
3 Correct 13 ms 19172 KB Output is correct
4 Correct 12 ms 19156 KB Output is correct
5 Correct 12 ms 19124 KB Output is correct
6 Correct 12 ms 19208 KB Output is correct
7 Correct 13 ms 19200 KB Output is correct
8 Correct 13 ms 19156 KB Output is correct
9 Correct 13 ms 19156 KB Output is correct
10 Correct 13 ms 19156 KB Output is correct
11 Correct 13 ms 19156 KB Output is correct
12 Correct 13 ms 19156 KB Output is correct
13 Correct 16 ms 19136 KB Output is correct
14 Correct 131 ms 19288 KB Output is correct
15 Correct 15 ms 19284 KB Output is correct
16 Correct 14 ms 19312 KB Output is correct
17 Correct 51 ms 19376 KB Output is correct
18 Correct 16 ms 19284 KB Output is correct
19 Correct 13 ms 19284 KB Output is correct
20 Correct 98 ms 19308 KB Output is correct
21 Correct 15 ms 19192 KB Output is correct
22 Correct 16 ms 19284 KB Output is correct
23 Correct 27 ms 19284 KB Output is correct
24 Correct 14 ms 19296 KB Output is correct
25 Correct 15 ms 19284 KB Output is correct
26 Correct 15 ms 19244 KB Output is correct
27 Correct 15 ms 19200 KB Output is correct
28 Correct 14 ms 19404 KB Output is correct
29 Correct 14 ms 19284 KB Output is correct
30 Correct 14 ms 19284 KB Output is correct
31 Correct 33 ms 19336 KB Output is correct
32 Correct 72 ms 19372 KB Output is correct
33 Correct 43 ms 19344 KB Output is correct
34 Correct 24 ms 19296 KB Output is correct
35 Correct 23 ms 19276 KB Output is correct
36 Correct 197 ms 19376 KB Output is correct
37 Correct 19 ms 19284 KB Output is correct
38 Correct 34 ms 19236 KB Output is correct
39 Correct 130 ms 19284 KB Output is correct
40 Correct 104 ms 19284 KB Output is correct
41 Correct 27 ms 19232 KB Output is correct
42 Correct 75 ms 19436 KB Output is correct
43 Correct 157 ms 19360 KB Output is correct
44 Correct 29 ms 19420 KB Output is correct
45 Correct 17 ms 19232 KB Output is correct
46 Correct 79 ms 19348 KB Output is correct
47 Correct 43 ms 19328 KB Output is correct
48 Correct 60 ms 19236 KB Output is correct
49 Correct 38 ms 19268 KB Output is correct
50 Correct 27 ms 19304 KB Output is correct
51 Correct 75 ms 19324 KB Output is correct
52 Correct 116 ms 19356 KB Output is correct
53 Correct 30 ms 19292 KB Output is correct
54 Correct 31 ms 19308 KB Output is correct
55 Correct 22 ms 19264 KB Output is correct
56 Correct 21 ms 19272 KB Output is correct
57 Correct 17 ms 19284 KB Output is correct
58 Correct 18 ms 19284 KB Output is correct
59 Correct 286 ms 26912 KB Output is correct
60 Correct 297 ms 26908 KB Output is correct
61 Correct 281 ms 26912 KB Output is correct
62 Correct 300 ms 26996 KB Output is correct
63 Correct 302 ms 26920 KB Output is correct
64 Correct 275 ms 27212 KB Output is correct
65 Correct 281 ms 26916 KB Output is correct
66 Correct 269 ms 26956 KB Output is correct
67 Correct 346 ms 26908 KB Output is correct
68 Correct 313 ms 27052 KB Output is correct
69 Correct 302 ms 27144 KB Output is correct
70 Correct 316 ms 26912 KB Output is correct
71 Correct 640 ms 27172 KB Output is correct
72 Execution timed out 3023 ms 32024 KB Time limit exceeded
73 Halted 0 ms 0 KB -