Submission #1031819

# Submission time Handle Problem Language Result Execution time Memory
1031819 2024-07-23T07:40:23 Z 변재우(#10964) Furniture (JOI20_furniture) C++17
0 / 100
2 ms 1628 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int Nmax=1010;
int N, M, Q, A[Nmax][Nmax], C[2*Nmax];
int B[Nmax][Nmax], B_[Nmax][Nmax];

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N>>M;
    for(int i=1; i<=N; i++) {
        for(int j=1; j<=M; j++) cin>>A[i][j];
    }
    B[1][1]=true;
    for(int i=1; i<=N; i++) for(int j=1; j<=M; j++) if(!A[i][j]) B[i][j]|=(B[i-1][j]|B[i][j-1]);
    B_[N][M]=true;
    for(int i=N; i>=1; i--) for(int j=M; j>=1; j--) if(!A[i][j]) B_[i][j]|=(B_[i+1][j]|B_[i][j+1]);
    for(int i=1; i<=N; i++) for(int j=1; j<=M; j++) B[i][j]&=B_[i][j], C[i+j]+=B[i][j];
    cin>>Q;
    while(Q--) {
        int i, j; cin>>i>>j;
        if(!B[i][j]) cout<<"1\n";
        else {
            if(C[i+j]>1) cout<<"1\n", C[i+j]--;
            else cout<<"0\n", C[i+j]--;
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Incorrect 2 ms 1628 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Incorrect 2 ms 1628 KB Output isn't correct
3 Halted 0 ms 0 KB -