This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 200000, X = 1000000000;
vector<array<int, 2>> skewers;
array<int, 4> rects[N];
bool tested[N];
int n;
array<int, 4> bounds() {
int x1 = X, x2 = 1, y1 = X, y2 = 1;
for (int i = 0; i < n; ++i) {
if (!tested[i]) {
auto [x3, x4, y3, y4] = rects[i];
x1 = min(x1, x4);
x2 = max(x2, x3);
y1 = min(y1, y4);
y2 = max(y2, y3);
}
}
return {x1, x2, y1, y2};
}
void solve(int k) {
if (k == 0) {
if (count(tested, tested + n, true) == n) {
for (auto [x, y] : skewers) {
cout << x << " " << y << "\n";
}
exit(0);
}
return;
}
auto [x1, x2, y1, y2] = bounds();
for (auto x : {x1, x2}) {
for (auto y : {y1, y2}) {
skewers.push_back({x, y});
vector<int> undo;
for (int i = 0; i < n; ++i) {
if (!tested[i]) {
auto [x3, x4, y3, y4] = rects[i];
if (x3 <= x && x <= x4) {
if (y3 <= y && y <= y4) {
tested[i] = true;
undo.push_back(i);
}
}
}
}
solve(k - 1);
for (auto i : undo) {
tested[i] = false;
}
skewers.pop_back();
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int k;
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> rects[i][0] >> rects[i][2] >> rects[i][1] >> rects[i][3];
}
solve(k);
cout << -1 << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |