Submission #648432

# Submission time Handle Problem Language Result Execution time Memory
648432 2022-10-06T13:18:26 Z 406 Hamburg Steak (JOI20_hamburg) C++17
21 / 100
3000 ms 29512 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];

void rec();

inline bool check() {
        return used.count() == 0;
}

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)) {
                        used[i] = false;
                        change.push_back(i);
                }
        }
        if (change.empty())
                return;
        points.emplace_back(x, y);

        rec();

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

}

void rec() {
        if (check() && (int) 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 = 2 * n;
                int mnU = 0;
                //assert(used.count() == 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);
                for (int h = minU + 1; h < maxD; h++)
                        add_point(minR, h);
        }
}

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;

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

Compilation message

hamburg.cpp: In function 'void rec()':
hamburg.cpp:51: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]
   51 |         if (points.size() >= k)
      |             ~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19284 KB Output is correct
2 Correct 14 ms 19284 KB Output is correct
3 Correct 13 ms 19252 KB Output is correct
4 Correct 12 ms 19276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 19284 KB Output is correct
2 Correct 13 ms 19268 KB Output is correct
3 Correct 12 ms 19244 KB Output is correct
4 Correct 12 ms 19284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19276 KB Output is correct
2 Correct 11 ms 19284 KB Output is correct
3 Correct 12 ms 19284 KB Output is correct
4 Correct 13 ms 19284 KB Output is correct
5 Correct 13 ms 19264 KB Output is correct
6 Correct 11 ms 19284 KB Output is correct
7 Correct 12 ms 19284 KB Output is correct
8 Correct 12 ms 19276 KB Output is correct
9 Correct 14 ms 19284 KB Output is correct
10 Correct 13 ms 19284 KB Output is correct
11 Correct 15 ms 19300 KB Output is correct
12 Correct 12 ms 19284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19272 KB Output is correct
2 Correct 12 ms 19284 KB Output is correct
3 Correct 13 ms 19284 KB Output is correct
4 Correct 12 ms 19284 KB Output is correct
5 Correct 12 ms 19280 KB Output is correct
6 Correct 12 ms 19284 KB Output is correct
7 Correct 11 ms 19208 KB Output is correct
8 Correct 14 ms 19268 KB Output is correct
9 Correct 14 ms 19284 KB Output is correct
10 Correct 16 ms 19264 KB Output is correct
11 Correct 12 ms 19284 KB Output is correct
12 Correct 12 ms 19252 KB Output is correct
13 Correct 15 ms 19284 KB Output is correct
14 Correct 344 ms 19292 KB Output is correct
15 Correct 18 ms 19284 KB Output is correct
16 Correct 15 ms 19284 KB Output is correct
17 Correct 719 ms 19288 KB Output is correct
18 Correct 14 ms 19284 KB Output is correct
19 Correct 14 ms 19268 KB Output is correct
20 Correct 1614 ms 19284 KB Output is correct
21 Correct 16 ms 19284 KB Output is correct
22 Correct 14 ms 19300 KB Output is correct
23 Correct 588 ms 19280 KB Output is correct
24 Correct 15 ms 19284 KB Output is correct
25 Correct 13 ms 19284 KB Output is correct
26 Correct 13 ms 19276 KB Output is correct
27 Correct 14 ms 19284 KB Output is correct
28 Correct 13 ms 19284 KB Output is correct
29 Correct 14 ms 19276 KB Output is correct
30 Correct 14 ms 19284 KB Output is correct
31 Correct 292 ms 19276 KB Output is correct
32 Correct 261 ms 19284 KB Output is correct
33 Correct 449 ms 19284 KB Output is correct
34 Correct 158 ms 19284 KB Output is correct
35 Correct 643 ms 19280 KB Output is correct
36 Correct 849 ms 19404 KB Output is correct
37 Correct 567 ms 19284 KB Output is correct
38 Correct 1220 ms 19272 KB Output is correct
39 Correct 1345 ms 19284 KB Output is correct
40 Correct 702 ms 19288 KB Output is correct
41 Correct 76 ms 19284 KB Output is correct
42 Correct 766 ms 19280 KB Output is correct
43 Correct 714 ms 19284 KB Output is correct
44 Correct 596 ms 19284 KB Output is correct
45 Correct 14 ms 19284 KB Output is correct
46 Correct 765 ms 19284 KB Output is correct
47 Correct 1364 ms 19284 KB Output is correct
48 Correct 1727 ms 19276 KB Output is correct
49 Correct 503 ms 19284 KB Output is correct
50 Correct 375 ms 19284 KB Output is correct
51 Correct 1156 ms 19404 KB Output is correct
52 Correct 702 ms 19280 KB Output is correct
53 Correct 485 ms 19296 KB Output is correct
54 Correct 568 ms 19276 KB Output is correct
55 Correct 915 ms 19288 KB Output is correct
56 Correct 904 ms 19284 KB Output is correct
57 Correct 855 ms 19416 KB Output is correct
58 Correct 907 ms 19284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19284 KB Output is correct
2 Correct 14 ms 19284 KB Output is correct
3 Correct 13 ms 19252 KB Output is correct
4 Correct 12 ms 19276 KB Output is correct
5 Correct 285 ms 29088 KB Output is correct
6 Correct 308 ms 29008 KB Output is correct
7 Correct 279 ms 29336 KB Output is correct
8 Correct 285 ms 29200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 19284 KB Output is correct
2 Correct 13 ms 19268 KB Output is correct
3 Correct 12 ms 19244 KB Output is correct
4 Correct 12 ms 19284 KB Output is correct
5 Correct 293 ms 29148 KB Output is correct
6 Correct 280 ms 29512 KB Output is correct
7 Correct 301 ms 29220 KB Output is correct
8 Correct 304 ms 29184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19276 KB Output is correct
2 Correct 11 ms 19284 KB Output is correct
3 Correct 12 ms 19284 KB Output is correct
4 Correct 13 ms 19284 KB Output is correct
5 Correct 13 ms 19264 KB Output is correct
6 Correct 11 ms 19284 KB Output is correct
7 Correct 12 ms 19284 KB Output is correct
8 Correct 12 ms 19276 KB Output is correct
9 Correct 14 ms 19284 KB Output is correct
10 Correct 13 ms 19284 KB Output is correct
11 Correct 15 ms 19300 KB Output is correct
12 Correct 12 ms 19284 KB Output is correct
13 Correct 295 ms 29156 KB Output is correct
14 Correct 299 ms 28840 KB Output is correct
15 Correct 293 ms 29084 KB Output is correct
16 Correct 309 ms 29056 KB Output is correct
17 Correct 291 ms 29036 KB Output is correct
18 Correct 286 ms 29112 KB Output is correct
19 Correct 304 ms 28964 KB Output is correct
20 Correct 303 ms 29020 KB Output is correct
21 Correct 400 ms 29268 KB Output is correct
22 Correct 339 ms 29016 KB Output is correct
23 Correct 311 ms 29236 KB Output is correct
24 Correct 330 ms 29396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19272 KB Output is correct
2 Correct 12 ms 19284 KB Output is correct
3 Correct 13 ms 19284 KB Output is correct
4 Correct 12 ms 19284 KB Output is correct
5 Correct 12 ms 19280 KB Output is correct
6 Correct 12 ms 19284 KB Output is correct
7 Correct 11 ms 19208 KB Output is correct
8 Correct 14 ms 19268 KB Output is correct
9 Correct 14 ms 19284 KB Output is correct
10 Correct 16 ms 19264 KB Output is correct
11 Correct 12 ms 19284 KB Output is correct
12 Correct 12 ms 19252 KB Output is correct
13 Correct 15 ms 19284 KB Output is correct
14 Correct 344 ms 19292 KB Output is correct
15 Correct 18 ms 19284 KB Output is correct
16 Correct 15 ms 19284 KB Output is correct
17 Correct 719 ms 19288 KB Output is correct
18 Correct 14 ms 19284 KB Output is correct
19 Correct 14 ms 19268 KB Output is correct
20 Correct 1614 ms 19284 KB Output is correct
21 Correct 16 ms 19284 KB Output is correct
22 Correct 14 ms 19300 KB Output is correct
23 Correct 588 ms 19280 KB Output is correct
24 Correct 15 ms 19284 KB Output is correct
25 Correct 13 ms 19284 KB Output is correct
26 Correct 13 ms 19276 KB Output is correct
27 Correct 14 ms 19284 KB Output is correct
28 Correct 13 ms 19284 KB Output is correct
29 Correct 14 ms 19276 KB Output is correct
30 Correct 14 ms 19284 KB Output is correct
31 Correct 292 ms 19276 KB Output is correct
32 Correct 261 ms 19284 KB Output is correct
33 Correct 449 ms 19284 KB Output is correct
34 Correct 158 ms 19284 KB Output is correct
35 Correct 643 ms 19280 KB Output is correct
36 Correct 849 ms 19404 KB Output is correct
37 Correct 567 ms 19284 KB Output is correct
38 Correct 1220 ms 19272 KB Output is correct
39 Correct 1345 ms 19284 KB Output is correct
40 Correct 702 ms 19288 KB Output is correct
41 Correct 76 ms 19284 KB Output is correct
42 Correct 766 ms 19280 KB Output is correct
43 Correct 714 ms 19284 KB Output is correct
44 Correct 596 ms 19284 KB Output is correct
45 Correct 14 ms 19284 KB Output is correct
46 Correct 765 ms 19284 KB Output is correct
47 Correct 1364 ms 19284 KB Output is correct
48 Correct 1727 ms 19276 KB Output is correct
49 Correct 503 ms 19284 KB Output is correct
50 Correct 375 ms 19284 KB Output is correct
51 Correct 1156 ms 19404 KB Output is correct
52 Correct 702 ms 19280 KB Output is correct
53 Correct 485 ms 19296 KB Output is correct
54 Correct 568 ms 19276 KB Output is correct
55 Correct 915 ms 19288 KB Output is correct
56 Correct 904 ms 19284 KB Output is correct
57 Correct 855 ms 19416 KB Output is correct
58 Correct 907 ms 19284 KB Output is correct
59 Correct 308 ms 27428 KB Output is correct
60 Correct 290 ms 27380 KB Output is correct
61 Correct 277 ms 27424 KB Output is correct
62 Correct 275 ms 27548 KB Output is correct
63 Correct 303 ms 27428 KB Output is correct
64 Correct 279 ms 27572 KB Output is correct
65 Correct 310 ms 27448 KB Output is correct
66 Correct 290 ms 27468 KB Output is correct
67 Correct 339 ms 27468 KB Output is correct
68 Correct 357 ms 27456 KB Output is correct
69 Correct 288 ms 27652 KB Output is correct
70 Correct 312 ms 27412 KB Output is correct
71 Correct 649 ms 27600 KB Output is correct
72 Execution timed out 3074 ms 27488 KB Time limit exceeded
73 Halted 0 ms 0 KB -