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 1642. 1D Maze

WA #4
Posted by S.Radjabov 7 Sep 2013 16:28
This is my code:

#include <iostream>
#include <cmath>

using namespace std;
int main()
{
int a[101], n, x, dis1 = 0, dis2 = 0, lb, rb;
bool flag = false, flag2 = false;

cin >> n >> x;

if ((x == 0))
flag2 = true;
else
{
if ( n == 0 )
flag = true;
}

for ( int i = 0; i < n; i++ )
{
cin >> a[i];
if ( (x > 0) && (a[i] < x) && (a[i] > 0) )
flag = true;

if ( (x < 0) && (a[i] > x)  && (a[i] < 0) )
flag = true;
}

if (flag)
cout << "Impossible" << endl;
else
{
lb = a[0];
rb = a[0];
for ( int i = 1; i < n; i++ )
{
if ( (a[i] > 0) && (a[i] > rb) && (a[i] > x) )
rb = a[i];

if ( (a[i] < 0) && (abs(a[i]) < abs(lb)) && (a[i] < x) )
lb = a[i];
}

if ( x > 0 )
{
dis1 = x;
dis2 = (int) abs(2*lb) + x;
}
else
{
dis1 = 2*rb + (int) abs(x);
dis2 = (int) abs(x);
}

if (flag2)
cout << "0 0" << endl;
else
cout << dis1 << " " << dis2 << endl;
}

system("PAUSE");
return 0;
}

---------------------------
I can't understand WHY WA#4