#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
int L[200000],D[200000],R[200000],U[200000];
vi adjList[200000];
vi ans1,ans2;
int colour[200000];
int doDFS(int u,int c) {
if (colour[u] != 0) return 0;
int i;
colour[u] = c+1;
for (i = 0; i < adjList[u].size(); i++) doDFS(adjList[u][i],!c);
return 0;
}
int main() {
int i;
int N,K;
scanf("%d %d",&N,&K);
for (i = 0; i < N; i++) scanf("%d %d %d %d",&L[i],&D[i],&R[i],&U[i]);
if (K == 1) {
int ml = 0,md = 0;
for (i = 0; i < N; i++) ml = max(ml,L[i]),md = max(md,D[i]);
printf("%d %d\n",ml,md);
}
else if (K == 2) {
int b = 0;
for (i = 0; i < N; i++) {
if (L[i] > L[b]) b = i;
}
for (i = 0; i < N; i++) {
if (R[i] < L[b]) {
adjList[i].pb(b);
adjList[b].pb(i);
}
}
for (i = 0; i < N; i++) {
if (R[i] < R[b]) b = i;
}
for (i = 0; i < N; i++) {
if (L[i] > R[b]) {
adjList[i].pb(b);
adjList[b].pb(i);
}
}
for (i = 0; i < N; i++) {
if (D[i] > D[b]) b = i;
}
for (i = 0; i < N; i++) {
if (U[i] < D[b]) {
adjList[i].pb(b);
adjList[b].pb(i);
}
}
for (i = 0; i < N; i++) {
if (U[i] < U[b]) b = i;
}
for (i = 0; i < N; i++) {
if (D[i] > U[b]) {
adjList[i].pb(b);
adjList[b].pb(i);
}
}
for (i = 0; i < N; i++) doDFS(i,0);
for (i = 0; i < N; i++) {
if (colour[i] == 1) ans1.pb(i);
else ans2.pb(i);
}
int ml = 0,md = 0;
for (i = 0; i < ans1.size(); i++) ml = max(ml,L[ans1[i]]),md = max(md,D[ans1[i]]);
printf("%d %d\n",ml,md);
ml = 0,md = 0;
for (i = 0; i < ans2.size(); i++) ml = max(ml,L[ans2[i]]),md = max(md,D[ans2[i]]);
printf("%d %d\n",ml,md);
}
return 0;
}
Compilation message
hamburg.cpp: In function 'int doDFS(int, int)':
hamburg.cpp:66:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (i = 0; i < adjList[u].size(); i++) doDFS(adjList[u][i],!c);
| ~~^~~~~~~~~~~~~~~~~~~
hamburg.cpp: In function 'int main()':
hamburg.cpp:124:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for (i = 0; i < ans1.size(); i++) ml = max(ml,L[ans1[i]]),md = max(md,D[ans1[i]]);
| ~~^~~~~~~~~~~~~
hamburg.cpp:127:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
127 | for (i = 0; i < ans2.size(); i++) ml = max(ml,L[ans2[i]]),md = max(md,D[ans2[i]]);
| ~~^~~~~~~~~~~~~
hamburg.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
72 | scanf("%d %d",&N,&K);
| ~~~~~^~~~~~~~~~~~~~~
hamburg.cpp:73:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
73 | for (i = 0; i < N; i++) scanf("%d %d %d %d",&L[i],&D[i],&R[i],&U[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
5 ms |
5120 KB |
Output is correct |
4 |
Correct |
5 ms |
5120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
6 ms |
5120 KB |
Output is correct |
4 |
Correct |
6 ms |
5120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
4992 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
4992 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
5 ms |
5120 KB |
Output is correct |
4 |
Correct |
5 ms |
5120 KB |
Output is correct |
5 |
Correct |
211 ms |
8092 KB |
Output is correct |
6 |
Correct |
154 ms |
8184 KB |
Output is correct |
7 |
Correct |
143 ms |
8184 KB |
Output is correct |
8 |
Correct |
193 ms |
8312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
6 ms |
5120 KB |
Output is correct |
4 |
Correct |
6 ms |
5120 KB |
Output is correct |
5 |
Correct |
205 ms |
16896 KB |
Output is correct |
6 |
Correct |
177 ms |
15016 KB |
Output is correct |
7 |
Correct |
173 ms |
16116 KB |
Output is correct |
8 |
Correct |
181 ms |
17520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
4992 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
4992 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |