#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX_STEAKS = (200 * 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 + 1].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 + 1].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
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 |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
360 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
188 ms |
6520 KB |
Output is correct |
6 |
Correct |
191 ms |
6520 KB |
Output is correct |
7 |
Correct |
189 ms |
6520 KB |
Output is correct |
8 |
Correct |
289 ms |
6520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
360 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |