이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
const int INF = 1e9 + 5, N = 2e5 + 5, M = 2005;
struct R {
int xl = -1, yl = -1, xr = INF, yr = INF;
bool is_empty() {
return xl > xr || yl > yr;
}
} rect[N];
int w[M][M], col[N];
int n, k;
R get_intersection(R a, R b) {
return {max(a.xl, b.xl), max(a.yl, b.yl), min(a.xr, b.xr), min(a.yr, b.yr)};
}
void dfs(int node, int c) {
col[node] = c;
for (int i = 0; i < n; i++) {
if (w[node][i] && !col[i]) {
dfs(i, 3 - c);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> rect[i].xl >> rect[i].yl >> rect[i].xr >> rect[i].yr;
}
if (k == 1) {
R inter;
for (int i = 0; i < n; i++) {
inter = get_intersection(inter, rect[i]);
}
cout << inter.xl << " " << inter.yl << "\n";
}
else if (k == 2) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
w[i][j] = get_intersection(rect[i], rect[j]).is_empty();
}
}
for (int i = 0; i < n; i++) {
if (!col[i]) {
dfs(i, 1);
}
}
R inter[2];
for (int i = 0; i < n; i++) {
inter[col[i] - 1] = get_intersection(inter[col[i] - 1], rect[i]);
}
for (int i = 0; i < 2; i++) {
cout << inter[i].xl << " " << inter[i].yl << "\n";
}
}
return 0;
}
# | 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... |