답안 #852043

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852043 2023-09-21T07:17:28 Z LucaIlie Furniture (JOI20_furniture) C++17
0 / 100
2 ms 2652 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1000;

int mat[MAX_N + 2][MAX_N + 2];

int main() {
    int n, m;

    cin >> n >> m;
    for ( int l = 0; l <= n + 1; l++ )
        mat[l][0] = mat[l][m + 1] = 1;
    for ( int c = 0; c <= m + 1; c++ )
        mat[0][c] = mat[n + 1][c] = 1;
    for ( int l = 1; l <= n; l++ ) {
        for ( int c = 1; c <= m; c++ )
            cin >> mat[l][c];
    }

    int v = 0, e = 0, f = 0;
    for ( int l = 1; l <= n; l++ ) {
        for ( int c = 1; c <= m; c++ ) {
            if ( mat[l][c] == 0 ) {
                v++;
                if ( mat[l][c + 1] == 0 )
                    e++;
                if ( mat[l + 1][c] == 0 )
                    e++;
                if ( mat[l + 1][c] + mat[l][c + 1] + mat[l + 1][c + 1] == 0 )
                    f++;
            }
        }
    }

    int q;
    cin >> q;
    while ( q-- ) {
        int l, c;

        cin >> l >> c;

        int cv = v, ce = e, cf = f;

        v--;
        if ( mat[l][c + 1] == 0 )
            e--;
        if ( mat[l][c - 1] == 0 )
            e--;
        if ( mat[l + 1][c] == 0 )
            e--;
        if ( mat[l - 1][c] == 0 )
            e--;
        if ( mat[l - 1][c] + mat[l][c - 1] + mat[l - 1][c - 1] == 0 )
            f--;
        if ( mat[l + 1][c] + mat[l][c - 1] + mat[l + 1][c - 1] == 0 )
            f--;
        if ( mat[l - 1][c] + mat[l][c + 1] + mat[l - 1][c + 1] == 0 )
            f--;
        if ( mat[l + 1][c] + mat[l][c + 1] + mat[l + 1][c + 1] == 0 )
            f--;
        mat[l][c] = 1;


        if ( v - e + f == 1 )
            cout << "1\n";
        else {
            cout << "0\n";
            v = cv;
            e = ce;
            f = cf;
            mat[l][c] = 0;
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -