# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1213074 | emptypringlescan | Hamburg Steak (JOI20_hamburg) | C++17 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
int n,k;
int arr[200005][4];
vector<pair<int,int> > ans;
bool sc(int nk){
if(nk==0){
for(int i=0; i<n; i++) if(arr[i][0]!=-1) return false;
return true;
}
int hm[5]={-1,-1,1e9,1e9,-1};
for(int i=0; i<n; i++){
if(arr[i][0]==-1) continue;
for(int j=0; j<2; j++){
hm[j]=max(hm[j],arr[i][j]);
}
for(int j=2; j<4; j++){
hm[j]=min(hm[j],arr[i][j]);
}
}
pair<int,int> pt;
vector<pair<int,int> > undo;
pt={hm[0],hm[1]};
ans.push_back(pt);
for(int i=0; i<n; i++){
if(arr[i][0]==-1) continue;
if(arr[i][0]<=pt.first&&pt.first<=arr[i][2]&&arr[i][1]<=pt.second&&pt.second<=arr[i][3]){
undo.push_back({i,arr[i][0]});
arr[i][0]=-1;
}
}
if(sc(nk-1)) return true;
ans.pop_back();
for(auto i:undo) arr[i.first][0]=i.second;
undo.clear();
pt={hm[2],hm[1]};
ans.push_back(pt);
for(int i=0; i<n; i++){
if(arr[i][0]==-1) continue;
if(arr[i][0]<=pt.first&&pt.first<=arr[i][2]&&arr[i][1]<=pt.second&&pt.second<=arr[i][3]){
undo.push_back({i,arr[i][0]});
arr[i][0]=-1;
}
}
if(sc(nk-1)) return true;
ans.pop_back();
for(auto i:undo) arr[i.first][0]=i.second;
undo.clear();
pt={hm[2],hm[3]};
ans.push_back(pt);
for(int i=0; i<n; i++){
if(arr[i][0]==-1) continue;
if(arr[i][0]<=pt.first&&pt.first<=arr[i][2]&&arr[i][1]<=pt.second&&pt.second<=arr[i][3]){
undo.push_back({i,arr[i][0]});
arr[i][0]=-1;
}
}
if(sc(nk-1)) return true;
ans.pop_back();
for(auto i:undo) arr[i.first][0]=i.second;
undo.clear();
pt={hm[0],hm[3]};
ans.push_back(pt);
for(int i=0; i<n; i++){
if(arr[i][0]==-1) continue;
if(arr[i][0]<=pt.first&&pt.first<=arr[i][2]&&arr[i][1]<=pt.second&&pt.second<=arr[i][3]){
undo.push_back({i,arr[i][0]});
arr[i][0]=-1;
}
}
if(sc(nk-1)) return true;
ans.pop_back();
for(auto i:undo) arr[i.first][0]=i.second;
undo.clear();
return false;
}
bool s4(){
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i=0; i<n; i++) for(int j=0; j<4; j++) cin >> arr[i][j];
if(k<4){
assert(sc(k));
for(auto i:ans) cout << i.first << ' ' << i.second << '\n';
}
}