Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.4 kB
2
Indexable
Never
#include <fstream>

using namespace std;

int x, y, n, l, dir[3000], v[100][100], x_start, y_start, x2, y2, nr1=1, nrzero;

int main()
{
    ifstream fin("zona2.in");
    ofstream fout("zona2.out");

    fin>>x>>y;
    x_start=x, y_start=y;
    fin>>n;
    fin>>l;

    v[x][y]=1;

    for(int i=1; i<=l; i++){
        fin>>dir[i];

        if(dir[i]==1){
            x--;
        }

        if(dir[i]==2){
            y++;
        }

        if(dir[i]==3){
            x++;
        }

        if(dir[i]==4){
            y--;
        }
        if(v[x][y]==1){
            x2=x;
            y2=y;
            break;
        }
        v[x][y]=1;
        nr1++;
    }

    for(int i=1; i<=l && (x_start!=x2 || y_start!=y2); i++){
        v[x_start][y_start]=0;
        nr1--;
        if(dir[i]==1){
            x_start--;
        }

        if(dir[i]==2){
            y_start++;
        }

        if(dir[i]==3){
            x_start++;
        }

        if(dir[i]==4){
            y_start--;
        }
    }
    
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if(v[i][j]==0 && v[i-1][j]==1 && v[i-1][j-1]==1 && v[i][j-1]==1){
                nrzero++;
                v[i][j]=1;
            }
        }
    }

    fout<<nr1<<endl<<nr1/2-1+nrzero;


    return 0;
}