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 <iostream>
#include <vector>
#include <cmath>
#include <cassert>
#include <random>
#include <algorithm>
#include <chrono>
using namespace std;
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 200000;
int const inf = 1000000000;
int const sigma = 4;
class Rect{
public:
int x;
int y;
int x2;
int y2;
Rect operator + (Rect a) {
return {max(x, a.x), max(y, a.y), min(x2, a.x2), min(y2, a.y2)};
}
bool valid(){
return (x <= x2) && (y <= y2);
}
ll area(){
return 1LL * (x2 - x + 1) * (y2 - y + 1);
}
} v[1 + nmax];
int main()
{
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<Rect> basic, high;
for(int i = 1;i <= n; i++) {
cin >> v[i].x >> v[i].y >> v[i].x2 >> v[i].y2;
basic.push_back(v[i]);
}
Rect base[1 + sigma];
while(true){
vector<Rect> ord;
ord.insert(ord.end(), high.begin(), high.end());
ord.insert(ord.end(), basic.begin(), basic.end());
high.clear();
basic.clear();
for(int j = 1;j <= k; j++)
base[j] = {1, 1, inf, inf};
for(int i = 0; i < ord.size(); i++){
Rect &curr = ord[i];
bool found = 0;
for(int j = 1;j <= k; j++){
Rect newp = curr + base[j];
if(newp.valid()) {
found = 1;
base[j] = base[j] + curr;
basic.push_back(curr);
break;
}
}
if(found == 0)
high.push_back(curr);
}
if(0 == high.size()){
for(int j = 1;j <= k; j++)
cout << base[j].x << " " << base[j].y << '\n';
return 0;
}
}
return 0;
}
Compilation message (stderr)
hamburg.cpp: In function 'int main()':
hamburg.cpp:63:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i = 0; i < ord.size(); i++){
| ~~^~~~~~~~~~~~
# | 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... |