제출 #467733

#제출 시각아이디문제언어결과실행 시간메모리
467733stefantagaFurniture (JOI20_furniture)C++14
100 / 100
452 ms16000 KiB
#include <bits/stdc++.h>

using namespace std;
int n,m,i,j,k,t,x,y,val,val2;
int din[1005][1005];
int dl[]= {1,-1,0,0};
int dc[]= {0,0,1,-1};
int fr[2005],nr;
vector <pair <int,int> > q;
bool interior (int x,int y)
{
    if (1<=x&&x<=n&&1<=y&&y<=m)
    {
        return 1;
    }
    return 0;
}
void update(int x,int y)
{
    int i,x2,y2,j;
    if (x==1&&y==1)
    {
        return;
    }
    if (x==n&&y==m)
    {
        return;
    }
    if (din[x][y]==0)
    {
        if (din[x+1][y]==1&&din[x][y+1]==1)
        {
            din[x][y]=1;
            fr[x+y]--;
            for (j=0; j<4; j++)
            {
                update(x+dl[j],y+dc[j]);
            }
        }
        else if (din[x-1][y]==1&&din[x][y-1]==1)
        {
            din[x][y]=1;
            fr[x+y]--;
            for (j=0; j<4; j++)
            {
                update(x+dl[j],y+dc[j]);
            }
        }
    }
}
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
#ifdef HOME
    ifstream cin("date.in");
    ofstream cout("date.out");
#endif // HOME
    cin>>n>>m;
    for (i=1; i<=n; i++)
    {
        for (j=1; j<=m; j++)
        {
            cin>>x;
            fr[i+j]++;
            if (x==1)
            {
                q.push_back({i,j});
            }
        }
    }
    for (i=0; i<=n+1; i++)
    {
        din[i][0]=din[i][m+1]=1;
    }
    for (i=0; i<=m+1; i++)
    {
        din[0][i]=din[n+1][i]=1;
    }
    for (i=0; i<q.size(); i++)
    {
        x=q[i].first;
        y=q[i].second;
        if (din[x][y]==1)
        {
            for (j=0; j<4; j++)
            {
                update(x+dl[j],y+dc[j]);
            }
        }
        else if (din[x][y]==0)
        {
            fr[x+y]--;
            din[x][y]=1;
            for (j=0; j<4; j++)
            {
                update(x+dl[j],y+dc[j]);
            }
        }
    }
    cin>>nr;
    for (i=1; i<=nr; i++)
    {
        cin>>x>>y;
        if (din[x][y]==1)
        {
            cout<<"1"<<'\n';
            for (j=0; j<4; j++)
            {
                update(x+dl[j],y+dc[j]);
            }
        }
        else
        {
            if (fr[x+y]==1)
            {
                cout<<"0"<<'\n';
            }
            else
            {
                fr[x+y]--;
                din[x][y]=1;
                for (j=0; j<4; j++)
                {
                    update(x+dl[j],y+dc[j]);
                }
                cout<<"1"<<'\n';
            }
        }
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

furniture.cpp: In function 'void update(int, int)':
furniture.cpp:20:9: warning: unused variable 'i' [-Wunused-variable]
   20 |     int i,x2,y2,j;
      |         ^
furniture.cpp:20:11: warning: unused variable 'x2' [-Wunused-variable]
   20 |     int i,x2,y2,j;
      |           ^~
furniture.cpp:20:14: warning: unused variable 'y2' [-Wunused-variable]
   20 |     int i,x2,y2,j;
      |              ^~
furniture.cpp: In function 'int main()':
furniture.cpp:80:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for (i=0; i<q.size(); i++)
      |               ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...