Submission #702231

# Submission time Handle Problem Language Result Execution time Memory
702231 2023-02-23T10:51:20 Z fadi57 Furniture (JOI20_furniture) C++14
100 / 100
1915 ms 63080 KB
#include<bits/stdc++.h>
using namespace std;
const int mx=1e3 + 10;

int dx[4]= {0,0,1,-1};
int dy[4]= {-1,1,0,0};
const int mod=998244353;
typedef long long ll;

int n,m;
set<int>ok[mx];
int c[mx][mx];
void goo(int x,int y)
{
    if(c[x-1][y]==0&&c[x-1][y+1]==1)
    {
        ok[x-1].erase(y) ;
        c[x-1][y] = 1 ;
        goo(x-1, y) ;

    }

    if(c[x][y-1]==0&&c[x+1][y-1]==1)
    {
        ok[x].erase(y-1) ;
        c[x][y-1] = 1 ;
        goo(x, y-1) ;

    }


    if(c[x][y+1]==0&&c[x-1][y+1]==1)
    {
        ok[x].erase(y+1) ;
        c[x][y+1] = 1 ;
        goo(x, y+1) ;

    }


    if(c[x+1][y]==0&&c[x+1][y-1]==1)
    {
        ok[x+1].erase(y) ;
        c[x+1][y] = 1 ;
        goo(x+1, y) ;

    }
}


bool check(int i,int j)
{

    int x = 1e9, y = -1e9 ;
    if(ok[i+1].size())
        x = *ok[i+1].begin() ;
    if(ok[i-1].size())
        y = *ok[i-1].rbegin() ;
    return (x < j || y > j) ;


}
void solve()
{
    //  cout<<(1<<4);
    cin>>n>>m;
    for(int i=0; i<=n+1; i++)
    {
        for(int j=0; j<=m+1; j++)
        {
            c[i][j]=1;
        }
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            cin>>c[i][j];
        }
    }

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            if(c[i][j]==0)
            {
                ok[i].insert(j) ;
            }

        }


    }
    for(int i = n ; i >= 1 ; --i)
	{
		for(int j = m ; j >= 1 ; --j)
		{
			if(c[i][j] == 1)
				goo(i , j) ;
		}
	}
    int q ;
    cin>>q ;
    while(q--)
    {
        int i, j ;
        cin>>i>>j ;
        if(c[i][j] == 1)
            cout<<1<<"\n" ;
        else if(check(i, j))
        {
            cout<<1<<"\n" ;
            c[i][j] = 1, ok[i].erase(j) ;
            goo(i, j) ;
        }
        else
            cout<<0<<"\n" ;
    }


}


int main()


{
solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 852 KB Output is correct
2 Correct 7 ms 876 KB Output is correct
3 Correct 9 ms 1108 KB Output is correct
4 Correct 15 ms 1180 KB Output is correct
5 Correct 18 ms 1248 KB Output is correct
6 Correct 20 ms 1220 KB Output is correct
7 Correct 18 ms 1328 KB Output is correct
8 Correct 19 ms 1340 KB Output is correct
9 Correct 19 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 852 KB Output is correct
2 Correct 7 ms 876 KB Output is correct
3 Correct 9 ms 1108 KB Output is correct
4 Correct 15 ms 1180 KB Output is correct
5 Correct 18 ms 1248 KB Output is correct
6 Correct 20 ms 1220 KB Output is correct
7 Correct 18 ms 1328 KB Output is correct
8 Correct 19 ms 1340 KB Output is correct
9 Correct 19 ms 1236 KB Output is correct
10 Correct 59 ms 3328 KB Output is correct
11 Correct 12 ms 1092 KB Output is correct
12 Correct 914 ms 50580 KB Output is correct
13 Correct 278 ms 41844 KB Output is correct
14 Correct 1726 ms 52892 KB Output is correct
15 Correct 1759 ms 53492 KB Output is correct
16 Correct 1749 ms 58024 KB Output is correct
17 Correct 1867 ms 61112 KB Output is correct
18 Correct 1882 ms 59596 KB Output is correct
19 Correct 1876 ms 62808 KB Output is correct
20 Correct 1915 ms 63040 KB Output is correct
21 Correct 1898 ms 63080 KB Output is correct