ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
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
Please, help!!!
Re: WA #4
Posted by Амир Меннибаев 15 Jan 2017 02:45
It's too hard code. The real solution is much easier/