Submission #771282

# Submission time Handle Problem Language Result Execution time Memory
771282 2023-07-02T19:12:26 Z MilosMilutinovic Hamburg Steak (JOI20_hamburg) C++14
2 / 100
267 ms 20596 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int inf = 1e9;
int n, k, l[N], d[N], r[N], u[N];
vector<int> sweep_line(int* a, int* b) {
    vector<array<int, 3>> ev;
    for (int i = 1; i <= n; i++) {
        ev.push_back({a[i], 0, i});
        ev.push_back({b[i], 1, i});
    }
    sort(ev.begin(), ev.end());
    set<int> st;
    int bal = 0;
    vector<int> res;
    for (auto& p : ev) {
        if (p[1] == 0) {
            bal += 1;
            st.insert(p[2]);
        } else {
            bal -= 1;
            if (st.find(p[2]) != st.end()) {
                res.push_back(p[0]);
                st.clear();
            }
        }
    }
    return res;
}
void print(vector<pair<int, int>> ans) {
    while (ans.size() < k) {
        ans.emplace_back(inf, inf);
    }
    for (auto& p : ans) {
        printf("%d %d\n", p.first, p.second);
    }
}
void brute(vector<int> xs, vector<int> ys) {
    bool swp = false;
    if (xs.size() < ys.size())
        swp = true, swap(xs, ys);
    if (swp) {
        for (int i = 1; i <= n; i++) {
            swap(l[i], d[i]);
            swap(r[i], u[i]);
        }
    }
    vector<int> ans;
    auto check = [&]() {
        for (int i = 1; i <= n; i++) {
            bool ok = false;
            for (int j = 0; j < xs.size(); j++) {
                if (!(l[i] <= xs[j] && xs[j] <= r[i])) continue;
                if (!(d[i] <= ans[j] && ans[j] <= u[i])) continue;
                ok = true;
            }
            if (!ok) return false;
        }
        return true;
    };
    function<void(int)> dfs = [&](int i) {
        if (i == xs.size()) {
            if (check()) {
                vector<pair<int, int>> res;
                for (int i = 0; i < xs.size(); i++) {
                    if (!swp)
                        res.emplace_back(xs[i], ans[i]);
                    else
                        res.emplace_back(ans[i], xs[i]);
                }
                print(res);
                exit(0);
            }
            return;
        }
        for (int v : ys) {
            ans.push_back(v);
            dfs(i + 1);
            ans.pop_back();
        }
    };
    dfs(0);
}
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d%d%d", &l[i], &d[i], &r[i], &u[i]);
    }
    vector<int> xs = sweep_line(l, r);
    vector<int> ys = sweep_line(d, u);
//    printf("xs = "); for (int v : xs) printf("%d ", v); printf("\n");
//    printf("ys = "); for (int v : ys) printf("%d ", v); printf("\n");
    if (max(xs.size(), ys.size()) <= 3) {
        brute(xs, ys);
        return 0;
    }
    printf("%d %d\n", xs[0], ys[0]);
}

Compilation message

hamburg.cpp: In function 'void print(std::vector<std::pair<int, int> >)':
hamburg.cpp:31:23: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     while (ans.size() < k) {
      |            ~~~~~~~~~~~^~~
hamburg.cpp: In lambda function:
hamburg.cpp:52:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |             for (int j = 0; j < xs.size(); j++) {
      |                             ~~^~~~~~~~~~~
hamburg.cpp: In lambda function:
hamburg.cpp:62:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         if (i == xs.size()) {
      |             ~~^~~~~~~~~~~~
hamburg.cpp:65:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |                 for (int i = 0; i < xs.size(); i++) {
      |                                 ~~^~~~~~~~~~~
hamburg.cpp: In function 'int main()':
hamburg.cpp:85:10: 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:87:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         scanf("%d%d%d%d", &l[i], &d[i], &r[i], &u[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 468 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 528 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Incorrect 3 ms 468 KB Unexpected end of file - int32 expected
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 468 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 247 ms 20592 KB Output is correct
6 Correct 260 ms 20544 KB Output is correct
7 Correct 250 ms 17528 KB Output is correct
8 Correct 267 ms 20596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 468 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 528 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Incorrect 3 ms 468 KB Unexpected end of file - int32 expected
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 468 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -