답안 #734141

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734141 2023-05-01T22:42:44 Z n0sk1ll Furniture (JOI20_furniture) C++17
0 / 100
2 ms 564 KB
#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
const int mod = 1000000007;







//Note to self: Check for overflow

bool c1[1003][1003]; //blokiran za gornji levi cosak?
bool c2[1003][1003]; //blokiran za dodnji desni cosak?
int slob[2006]; //koliko slobodnih na datoj dijagonali

void Put1(int x, int y)
{
    if (c1[x][y]) return;
    if (!c2[x][y]) slob[x+y]--;

    c1[x][y]=1;

    if (c1[x-1][y+1]) Put1(x-1,y);
    if (c1[x+1][y-1]) Put1(x,y-1);
}

void Put2(int x, int y)
{
    if (c2[x][y]) return;
    if (!c1[x][y]) slob[x+y]--;

    c2[x][y]=1;

    if (c2[x-1][y+1]) Put2(x,y+1);
    if (c2[x+1][y-1]) Put2(x+1,y);
}

int main()
{
    FAST;

    int n,m; cin>>n>>m;
    fff(i,0,n+1) fff(j,0,m+1) c1[i][j]=1,c2[i][j]=1;
    fff(i,1,n) fff(j,1,m) cin>>c1[i][j],c2[i][j]=c1[i][j];

    fff(i,1,n) fff(j,1,m) if (!(i==1 && j==1) && c1[i-1][j] && c1[i][j-1]) c1[i][j]=1;
    bfff(i,1,n) bfff(j,1,m) if (!(i==n && j==m) && c2[i+1][j] && c2[i][j+1]) c2[i][j]=1;

    fff(i,1,n) fff(j,1,m) if (!c1[i][j] && !c2[i][j]) slob[i+j]++;

    /*cout<<endl;
    fff(i,1,n)
    {
        fff(j,1,m) cout<<c1[i][j]<<" ";
        cout<<endl;
    }

    cout<<endl;
    fff(i,1,n)
    {
        fff(j,1,m) cout<<c2[i][j]<<" ";
        cout<<endl;
    } cout<<endl;*/

    int q; cin>>q;
    while (q--)
    {
        int x,y; cin>>x>>y;
        if (c1[x][y] || c2[x][y] || slob[x+y]>1) Put1(x,y),Put2(x,y),cout<<1<<"\n";
        else cout<<0<<"\n";
    }
}

//Note to self: Check for overflow
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Incorrect 2 ms 564 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Incorrect 2 ms 564 KB Output isn't correct
3 Halted 0 ms 0 KB -