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 1033. Labyrinth

Show all messages Hide all messages

Where is my mistake?????? Sega 31 Jul 2003 12:26
This is my program:

#include<iostream.h>

int **a;

int main()
{
    int n,i,j,f=0;
    char c;
    cin >> n; cin.get(c);
    a=new int* [n+2];
    a[0]=new int [n+2];
    a[n+1]=new int [n+2];
    for (i=1; i<=n; i++)
    {
        a[i]=new int [n+2];
        for (j=1; j<=n; j++)
        {
            cin.get(c);
            while ((c!='.')&&(c!='#'))
                cin.get(c);
            if (c=='.') a[i][j]=0;
            else a[i][j]=1;
        }
        cin.get(c);
    }
    for (i=0; i<=n+1; i++)
    {
        a[0][i]=1; a[n+1][i]=1;
        a[i][0]=1; a[i][n+1]=1;
    }
    int state=1;
    long len=-3;
    i=1; j=1;
    while ((i!=1)||(j!=1)||(state!=4))
    {
        if ((i==n)&&(j==n)) f=1;
        if (state==1)
        {
            if (a[i-1][j])
            {
                len++;
                if (a[i][j+1]) state=2;
                else j++;
            } else {state=4; i--;}
        } else
        if (state==2)
        {
            if (a[i][j+1])
            {
                len++;
                if (a[i+1][j]) state=3;
                else i++;
            } else {state=1; j++;}
        } else
        if (state==3)
        {
            if (a[i+1][j])
            {
                len++;
                if (a[i][j-1]) state=4;
                else j--;
            } else {state=2; i++;}
        } else
        {
            if (a[i][j-1])
            {
                len++;
                if (a[i-1][j]) state=1;
                else i--;
            } else {state=3; j--;}
        }
    }
    if (!f)
    {
        i=n; j=n; state=3; len++;
    while ((i!=n)||(j!=n)||(state!=2))
    {
        if ((i==n)&&(j==n)) f=1;
        if (state==1)
        {
            if (a[i-1][j])
            {
                len++;
                if (a[i][j+1]) state=2;
                else j++;
            } else {state=4; i--;}
        } else
        if (state==2)
        {
            if (a[i][j+1])
            {
                len++;
                if (a[i+1][j]) state=3;
                else i++;
            } else {state=1; j++;}
        } else
        if (state==3)
        {
            if (a[i+1][j])
            {
                len++;
                if (a[i][j-1]) state=4;
                else j--;
            } else {state=2; i++;}
        } else
        {
            if (a[i][j-1])
            {
                len++;
                if (a[i-1][j]) state=1;
                else i--;
            } else {state=3; j--;}
        }
    }
    }
    cout << 9*len;
    return 0;
}

I check my program on all tests on forum, it works right!
If somebody can help me, show me my mistake, please.
Beforehand thanks.