Submission #1092845

# Submission time Handle Problem Language Result Execution time Memory
1092845 2024-09-25T08:45:01 Z maxFedorchuk Furniture (JOI20_furniture) C++17
0 / 100
1 ms 856 KB
#include <bits/stdc++.h>
using namespace std;

const long long MX=2e3+10;
int a[MX][MX],kvil[MX];

int corx[4]={0,0,1,-1};
int cory[4]={1,-1,0,0};

int n,m;

void upd(int x,int y)
{
    if(a[x][y])
    {
        return;
    }

    a[x][y]=1;
    kvil[x+y]--;

    for(int i=0;i<4;i++)
    {
        int nx=x+corx[i];
        int ny=y+cory[i];

        if(!(nx==1 && ny==1) && !(nx==n && ny==m) && ((a[nx-1][ny]==1 && a[nx][ny-1]==1) || (a[nx+1][ny]==1 && a[nx][ny+1]==1)))
        {
            upd(nx,ny);
        }
    }
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin>>n>>m;

    for(int i=0;i<=n+1;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(i!=0 && j!=0 && i!=n+1 && j!=m+1)
            {
                kvil[i+j]++;
            }
            else
            {
                a[i][j]=1;
            }
        }
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            int zn;
            cin>>zn;

            if(zn==1)
            {
                if(!a[i][j])
                {
                    upd(i,j);
                }
            }
        }
    }

    int q;
    cin>>q;

    while(q--)
    {
        int x,y;
        cin>>x>>y;

        if(a[x][y]==1)
        {
            cout<<"1\n";
            continue;
        }

        if(kvil[x+y]==1)
        {
            cout<<"0\n";
        }
        else
        {
            upd(x,y);
            cout<<"1\n";
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Incorrect 1 ms 856 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Incorrect 1 ms 856 KB Output isn't correct
3 Halted 0 ms 0 KB -