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 <cstdio>
#include <algorithm>
using namespace std;
const int MAX_STEAKS = (1000 * 1000);
int Steaks[MAX_STEAKS][4];
int PossiblesPiques[4][2];
int Choisi[4];
pair <int, int> Horizontaux[MAX_STEAKS + 1];
pair <int, int> Verticaux[MAX_STEAKS + 1];
int nbSteaks, nbPiques;
void Read() {
scanf("%d%d", &nbSteaks, &nbPiques);
for (int i = 0; i < nbSteaks; i ++)
{
for (int j = 0; j < 4; j ++)
{
scanf("%d", &Steaks[i][j]);
}
Horizontaux[i] = make_pair(Steaks[i][0], ++ Steaks[i][2]);
Verticaux[i] = make_pair(Steaks[i][1], ++ Steaks[i][3]);
}
sort(Horizontaux, Horizontaux + nbSteaks);
sort(Verticaux, Verticaux + nbSteaks);
return;
}
void TraiteHorizontaux() {
int nbPik = 0;
int act = 0;
int minfin = Horizontaux[0].second;
while (act < nbSteaks)
{
if (Horizontaux[act].first >= minfin)
{
PossiblesPiques[nbPik ++][0] = minfin - 1;
minfin = Horizontaux[act].second;
}
minfin = min(minfin, Horizontaux[act].second);
act ++;
}
PossiblesPiques[nbPik ++][0] = minfin - 1;
for (int i = nbPik; i < nbPiques; i ++)
{
PossiblesPiques[i][0] = PossiblesPiques[i - 1][0];
}
return;
}
void TraiteVerticaux() {
int nbPik = 0;
int act = 0;
int minfin = Verticaux[0].second;
while (act < nbSteaks)
{
if (Verticaux[act].first >= minfin)
{
PossiblesPiques[nbPik ++][1] = minfin - 1;
minfin = Verticaux[act].second;
}
minfin = min(minfin, Verticaux[act].second);
act ++;
}
PossiblesPiques[nbPik ++][1] = minfin - 1;
for (int i = nbPik; i < nbPiques; i ++)
{
PossiblesPiques[i][1] = PossiblesPiques[i - 1][1];
}
return;
}
bool Inter(int i, int lig, int col) {
return Steaks[i][0] <= lig && lig < Steaks[i][2] && Steaks[i][1] <= col && col < Steaks[i][3];
}
bool Verify() {
for (int i = 0; i < nbSteaks; i ++)
{
bool t = false;
for (int j = 0; j < nbPiques; j ++)
{
if (Inter(i, PossiblesPiques[j][0], Choisi[j]))
{
t = true;
}
}
if (!t)
{
return false;
}
}
return true;
}
bool Choose(int cur) {
if (cur == nbPiques)
{
return Verify();
}
for (int i = 0; i < nbPiques; i ++)
{
Choisi[cur] = PossiblesPiques[i][1];
if (Choose(cur + 1))
{
return true;
}
}
return false;
}
void Solve() {
if (Choose(0))
{
//printf("42\n");
}
for (int i = 0; i < nbPiques; i ++)
{
printf("%d %d\n", PossiblesPiques[i][0], Choisi[i]);
}
return;
}
void Print() {
for (int i = 0; i < nbSteaks; i ++)
{
//printf("%d %d\n", Horizontaux[i].first, Horizontaux[i].second);
}
for (int i = 0; i < nbSteaks; i ++)
{
//printf("%d %d\n", Verticaux[i].first, Verticaux[i].second);
}
for (int i = 0; i < nbPiques; i ++)
{
//printf("%d %d\n", PossiblesPiques[i][0], PossiblesPiques[i][1]);
}
return;
}
int main() {
Read();
TraiteHorizontaux();
TraiteVerticaux();
Solve();
Print();
return 0;
}
Compilation message (stderr)
hamburg.cpp: In function 'void Read()':
hamburg.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
20 | scanf("%d%d", &nbSteaks, &nbPiques);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hamburg.cpp:25:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
25 | scanf("%d", &Steaks[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# | 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... |