ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1112. Cover

WA #6
Posted by Arlen 2 Apr 2021 07:24
Hello. My program passes all tests from the forum, but I still get WA6.

I do brute force

First, I go through all the elements that are to the right of the current one, then everything that is to the left

can anyone have any tests?

here is y code is needed:

#include <iostream>

using namespace std;

int n, result = 0, sizeHelpArray = 0, sizeAnswerArray;

//initialization and sorting on the left border
void Init()
{
int i, j;
cin >> n;
for (i = 0; i < n; i++)
{
cin >> line[i][0] >> line[i][1];
if (line[i][0] > line[i][1])
swap(line[i][0], line[i][1]);
}

for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (line[j][0] < line[i][0])
{
swap(line[i][0], line[j][0]);
swap(line[i][1], line[j][1]);
}
if(line[j][0] == line[i][0])
if (line[j][1] < line[i][1])
{
swap(line[i][0], line[j][0]);
swap(line[i][1], line[j][1]);
}
}
}
}

{
sizeHelpArray++;
helpArray[sizeHelpArray][0] = line[index][0];
helpArray[sizeHelpArray][1] = line[index][1];
}

//to record the best current result

{
int i;
for (i = 0; i < sizeHelpArray + 1; i++)
{
}
}

{
for (int i = 0; i <= sizeAnswerArray; i++)
{
for (int j = i + 1; j <= sizeAnswerArray; j++)
{
{
}
{
}
}
}
}

void Solve()
{
int i, x, tmp = 1, currentPoint;
//starting from the first element ..
for (x = 0; x < n; x++)
{
sizeHelpArray = 0;
tmp = 1;
memset(helpArray, 0, sizeof(helpArray));
//I write the current element to an auxiliary array
helpArray[sizeHelpArray][0] = line[x][0];
helpArray[sizeHelpArray][1] = line[x][1];
currentPoint = line[x][1];
//Checking items to the right of the current one
for (i = x + 1; i < n; i++)
{
if (line[i][0] >= currentPoint)
{
tmp++;
currentPoint = line[i][1];
}
}

currentPoint = line[x][0];
int border;
border = line[x][0];
bool first = true;
//Checking items to the left of the current one
for (int j = 0; j < x; j++)
{
if (line[j][1] <= currentPoint && first)
{
tmp++;
currentPoint = line[j][1];
first = false;
}
else if (first == false && line[j][0] >= currentPoint && line[j][1] <= border)
{
tmp++;
currentPoint = line[j][1];
}
}
//If the result is better than the previous one, then I save it.
if (tmp > result)
{
result = tmp;
}
}

cout << result << endl;
for (int i = 0; i <= sizeAnswerArray; i++)
}

int main()
{
Init();
Solve();
return 0;
}

Edited by author 02.04.2021 07:26

Edited by author 02.04.2021 07:26

Edited by author 02.04.2021 07:37

Edited by author 02.04.2021 07:37